diff --git a/R/Design.R b/R/Design.R index ec4a7854..8070d6cf 100644 --- a/R/Design.R +++ b/R/Design.R @@ -109,7 +109,7 @@ Design = R6Class("Design", pcol = self$data[[dd$on[j]]] # we are ok if parent was active and cond on parent is OK not_ok = which(is.na(pcol) | !dd$cond[[j]]$test(pcol)) - set(self$data, not_ok, j = param_id, value = as(NA, param$storage_type)) + set(self$data, not_ok, j = param_id, value = as_type(NA, param$storage_type)) } } } diff --git a/R/Sampler1D.R b/R/Sampler1D.R index 3e51de1f..c45d2661 100644 --- a/R/Sampler1D.R +++ b/R/Sampler1D.R @@ -30,7 +30,7 @@ Sampler1D = R6Class("Sampler1D", inherit = Sampler, # abstract base class private = list( # create a 1-col-dt, named by param-id, from a data vector (from sampling), and enforce storage type as_dt_col = function(x) { - x = get(sprintf("as.%s", self$param$storage_type), mode = "function", envir = baseenv())(x) + x = as_type(x, self$param$storage_type) set_names(data.table(x), self$param$id) } ) diff --git a/R/helper.R b/R/helper.R index 9080921e..1585a1de 100644 --- a/R/helper.R +++ b/R/helper.R @@ -30,3 +30,13 @@ transpose = function(data, ps = NULL, filter_na = TRUE, trafo = TRUE) { } return(xs) } + +as_type = function(x, type) { + switch(type, + logical = as.logical(x), + integer = as.integer(x), + numeric = as.numeric(x), + character = as.character(x), + stopf("Invalid storage type '%s'", type) + ) +} diff --git a/README.md b/README.md index dcadb6aa..5d91c6ba 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ paradox ======= Package website: [release](https://paradox.mlr-org.com/) \| -[dev](https://paradox.mlr-org.com/dev) +[dev](https://paradox.mlr-org.com/dev/) Universal Parameter Space Description and Tools. @@ -84,26 +84,26 @@ Properties of the parameters within the `ParamSet`: ps$levels #> $z #> NULL - #> + #> #> $x #> NULL - #> + #> #> $flag #> [1] TRUE FALSE - #> + #> #> $methods #> [1] "a" "b" "c" ps$nlevels - #> z x flag methods + #> z x flag methods #> 3 Inf 2 3 ps$is_number - #> z x flag methods + #> z x flag methods #> TRUE TRUE FALSE FALSE ps$lower - #> z x flag methods + #> z x flag methods #> 1 -10 NA NA ps$upper - #> z x flag methods + #> z x flag methods #> 3 10 NA NA ### Parameter Checks @@ -151,15 +151,15 @@ inside the transformation. #> [[1]] #> [[1]]$z #> [1] 0.125 - #> + #> #> [[1]]$x #> [1] 0.4137243 - #> - #> + #> + #> #> [[2]] #> [[2]]$z #> [1] 0.5 - #> + #> #> [[2]]$x #> [1] 0.3688455