Skip to contents

This emulates ParamSetCollection$new(sets), except that the result is a flat ParamSet, not a ParamSetCollection. The resulting object is decoupled from the input ParamSet objects: Unlike ParamSetCollection, changing $values of the resulting object will not change the input ParamSet $values by reference.

This emulates ParamSetCollection$new(sets), which in particular means that the resulting ParamSet has all the Domains from the input sets, but some $ids are changed: If the ParamSet is given in sets with a name, then the Domains will have their <id> changed to <name in "sets">.<id>. This is also reflected in deps.

The c() operator, applied to ParamSets, is a synony for ps_union().

Usage

ps_union(sets, tag_sets = FALSE, tag_params = FALSE)

Arguments

sets

(list of ParamSet)
This may be a named list, in which case non-empty names are prefixed to parameters in the corresponding ParamSet.

tag_sets

(logical(1))
Whether to add tags of the form "set_<set_id>" to each parameter originating from a given ParamSet given with name <name in "sets">.

tag_params

(logical(1))
Whether to add tags of the form "param_<param_id>" to each parameter with original ID <param_id>.

Examples

ps1 = ps(x = p_dbl())
ps1$values = list(x = 1)

ps2 = ps(y = p_lgl())

pu = ps_union(list(ps1, ps2))
# same as:
pu = c(ps1, ps2)

pu
#> <ParamSet(2)>
#>        id    class lower upper nlevels        default  value
#>    <char>   <char> <num> <num>   <num>         <list> <list>
#> 1:      x ParamDbl  -Inf   Inf     Inf <NoDefault[0]>      1
#> 2:      y ParamLgl    NA    NA       2 <NoDefault[0]>       

pu$values
#> $x
#> [1] 1
#> 

pu$values$x = 2
pu$values
#> $x
#> [1] 2
#> 

# p1 is unchanged:
ps1$values
#> $x
#> [1] 1
#> 

# Prefixes automatically created for named elements.
# This allows repeating components.
pu2 = c(one = ps1, two = ps1, ps2)
pu2
#> <ParamSet(3)>
#>        id    class lower upper nlevels        default  value
#>    <char>   <char> <num> <num>   <num>         <list> <list>
#> 1:  one.x ParamDbl  -Inf   Inf     Inf <NoDefault[0]>      1
#> 2:  two.x ParamDbl  -Inf   Inf     Inf <NoDefault[0]>      1
#> 3:      y ParamLgl    NA    NA       2 <NoDefault[0]>       

pu2$values
#> $one.x
#> [1] 1
#> 
#> $two.x
#> [1] 1
#>