Skip to content

Commit

Permalink
fixing evaluation of par.vals
Browse files Browse the repository at this point in the history
  • Loading branch information
kerschke committed Aug 19, 2016
1 parent bbec8cf commit db19414
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
18 changes: 8 additions & 10 deletions R/evaluateParamExpressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' a given dictionary.
#'
#' @param obj [\code{\link{Param}} | \code{\link[ParamHelpers]{ParamSet}} | \code{list}]\cr
#' Parameter, parameter set or list of parameters. Expressions within \code{length},
#' Parameter, parameter set or list of parameter values. Expressions within \code{length},
#' \code{lower} or \code{upper} boundaries, \code{default} or \code{value} will be
#' evaluated using the provided dictionary (\code{dict}).
#' @template arg_dict
Expand All @@ -26,10 +26,10 @@
#' evaluateParamExpressions(ps, dict = list(data = iris))
#'
#' par.vals = list(
#' makeNumericVectorParam("x", len = expression(k), default = expression(n)),
#' makeIntegerParam("y", lower = 1, upper = 2)
#' x = expression(k),
#' y = 5
#' )
#' evaluateParamExpressions(par.vals, dict = list(k = 3, n = 10))
#' evaluateParamExpressions(par.vals, dict = list(k = 3))
evaluateParamExpressions = function(obj, dict = NULL) {
UseMethod("evaluateParamExpressions")
}
Expand Down Expand Up @@ -77,10 +77,8 @@ evaluateParamExpressions.list = function(obj, dict = NULL) {
assertClass(obj, "list")
assertList(dict, names = "unique", null.ok = TRUE)
ids = names(obj)
# evaluate all parameters separately
obj = lapply(obj, function(par) {
evaluateParamExpressions(obj = par, dict = dict)
})
names(obj) = ids
return(obj)
# evaluate all parameter values separately
setNames(lapply(obj, function(par) {
eval(expr = par, envir = dict)
}), ids)
}
8 changes: 4 additions & 4 deletions man/evaluateParamExpressions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/testthat/test_evaluateParamExpressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ test_that("expressions", {
expect_error(evaluateParamExpressions(ps))
expect_error(evaluateParamExpressions(ps, dict = list(p = 3)))
expect_error(evaluateParamExpressions(ps, dict = list(z = "b")))
pv = list(x = expression(k), y = 5)
expect_identical(evaluateParamExpressions(pv, dict = list(k = 3)), list(x = 3, y = 5))
})

0 comments on commit db19414

Please sign in to comment.