Skip to content

Commit

Permalink
Merge branch 'master' of github.com:berndbischl/ParamHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
berndbischl committed Jan 5, 2017
2 parents 85bdfa2 + be7d662 commit 82b8149
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
6 changes: 0 additions & 6 deletions R/LearnerParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ NULL
makeLearnerParam = function(p, when) {
assertChoice(when, c("train", "predict", "both"))
p$when = when
if (isNumeric(p, include.int = TRUE) && isScalarNA(p$len)) {
if (!is.expression(p$lower) && length(p$lower) != 1L)
stopf("For learner vector param '%s' with unspecified length (NA), bound 'lower' can only be a scalar, but has length:", p$id, length(p$lower))
if (!is.expression(p$lupper) && length(p$upper) != 1L)
stopf("For learner vector param '%s' with unspecified length (NA), bound 'upper' can only be a scalar, but has length:", p$id, length(p$upper))
}
class(p) = c("LearnerParam", "Param")
return(p)
}
Expand Down
4 changes: 2 additions & 2 deletions R/aParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ makeParam = function(id, type, learner.param, len = 1L, lower = NULL, upper = NU
# the following check also ensures that if len=NA, the lower and upper must be scalars
if (!is.expression(len) && !is.expression(lower)) {
if (length(lower) %nin% c(1L, len))
stopf("For param '%s' length 'lower' must be either 1 or length of param, not:", id, length(lower))
stopf("For param '%s' length 'lower' must be either 1 or length of param, not: %i", id, length(lower))
}
if (!is.expression(len) && !is.expression(upper)) {
if (length(upper) %nin% c(1L, len))
stopf("For param '%s' length 'upper' must be either 1 or length of param, not:", id, length(upper))
stopf("For param '%s' length 'upper' must be either 1 or length of param, not: %i", id, length(upper))
}
}
if (isDiscreteTypeString(type)) {
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test_LearnerParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ test_that("num vec", {
# defaults
p = makeNumericVectorLearnerParam(id = "x", allow.inf = TRUE, default = Inf)
expect_error(makeNumericVectorLearnerParam(id = "x", allow.inf = FALSE, default = Inf), "feasible")
expect_error(makeNumericVectorLearnerParam(id = "x", allow.inf = FALSE, default = c(0,0), lower = c(-1,-1)), "'lower' must be either 1 or length of param")
expect_error(makeNumericVectorLearnerParam(id = "x", allow.inf = FALSE, default = c(0,0), upper = c(1,1)), "'upper' must be either 1 or length of param")
})

test_that("int vec", {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_isFeasible.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ test_that("length of vectors", {
test_that("isFeasible works when len=NA, and default is given (with other lengths than in isFeasible)", {
p = makeIntegerVectorLearnerParam(id = "test", default = c(10,10), lower = 0)
expect_true(isFeasible(p, c(10,10,10)))
expect_false(isFeasible(p, c(-1)))
})

0 comments on commit 82b8149

Please sign in to comment.