Skip to contents

expand_list() creates a cross product of multiple lists. It works like tidyr::expand_grid(), but you do not need to wrap the arguments in an extra list(). Use it to build combinations of analysis parameters.

Usage

expand_list(...)

Arguments

...

Named arguments. Each one holds a vector or a list of values to combine.

Value

A list of lists. Each inner list holds one combination of values from the input arguments.

See also

Plan. Its add_argset_from_list() method takes this list. See vignette("adding_analyses"), which builds argsets with plnr::expand_list(), then applies one action function to all of them.

Examples

# Create combinations of parameters
combinations <- plnr::expand_list(
  a = 1:2,
  b = c("a", "b")
)

# View the combinations
str(combinations)
#> List of 4
#>  $ :List of 2
#>   ..$ a: int 1
#>   ..$ b: chr "a"
#>  $ :List of 2
#>   ..$ a: int 1
#>   ..$ b: chr "b"
#>  $ :List of 2
#>   ..$ a: int 2
#>   ..$ b: chr "a"
#>  $ :List of 2
#>   ..$ a: int 2
#>   ..$ b: chr "b"

# Compare with tidyr::expand_grid
tidyr::expand_grid(list(
  a = 1:2,
  b = c("a", "b")
))
#> # A tibble: 2 × 1
#>   `list(a = 1:2, b = c("a", "b"))`
#>   <named list>                    
#> 1 <int [2]>                       
#> 2 <chr [2]>