R/generate.R
The commands in workflow plan data frames can have
wildcard symbols that can stand for datasets, parameters, function
arguments, etc. These wildcards can be evaluated over a set of
possible values using evaluate_plan
.
evaluate_plan(plan, rules = NULL, wildcard = NULL, values = NULL, expand = TRUE)
plan | workflow plan data frame, similar to one produced by
|
---|---|
rules | Named list with wildcards as names and vectors of
replacements
as values. This is a way to evaluate multiple wildcards at once.
When not |
wildcard | character scalar denoting a wildcard placeholder |
values | vector of values to replace the wildcard
in the drake instructions. Will be treated as a character vector.
Must be the same length as |
expand | If |
A workflow plan data frame with the wildcards evaluated.
Specify a single wildcard with the wildcard
and values
arguments. In each command, the text in
wildcard
will be replaced by each value in values
in turn. Specify multiple wildcards with the rules
argument,
which overrules wildcard
and values
if
not NULL
. Here, rules
should be a list with wildcards
as names and vectors of possible values as list elements.
# Create the part of the workflow plan for the datasets. datasets <- drake_plan( small = simulate(5), large = simulate(50)) # Create a template workflow plan for the analyses. methods <- drake_plan( regression1 = reg1(dataset__), regression2 = reg2(dataset__)) # Evaluate the wildcards in the template # to produce the actual part of the workflow plan # that encodes the analyses of the datasets. # Create one analysis for each combination of dataset and method. evaluate_plan(methods, wildcard = "dataset__", values = datasets$target)#> # A tibble: 4 x 2 #> target command #> <chr> <chr> #> 1 regression1_small reg1(small) #> 2 regression1_large reg1(large) #> 3 regression2_small reg2(small) #> 4 regression2_large reg2(large)# Only choose some combinations of dataset and analysis method. ans <- evaluate_plan(methods, wildcard = "dataset__", values = datasets$target, expand = FALSE) ans#> # A tibble: 2 x 2 #> target command #> <chr> <chr> #> 1 regression1 reg1(small) #> 2 regression2 reg2(large)# For the complete workflow plan, row bind the pieces together. my_plan <- rbind(datasets, ans) my_plan#> # A tibble: 4 x 2 #> target command #> <chr> <chr> #> 1 small simulate(5) #> 2 large simulate(50) #> 3 regression1 reg1(small) #> 4 regression2 reg2(large)# Workflow plans can have multiple wildcards. # Each combination of wildcard values will be used # Except when expand is FALSE. x <- drake_plan(draws = rnorm(mean = Mean, sd = Sd)) evaluate_plan(x, rules = list(Mean = 1:3, Sd = c(1, 10)))#> # A tibble: 6 x 2 #> target command #> <chr> <chr> #> 1 draws_1_1 rnorm(mean = 1, sd = 1) #> 2 draws_1_10 rnorm(mean = 1, sd = 10) #> 3 draws_2_1 rnorm(mean = 2, sd = 1) #> 4 draws_2_10 rnorm(mean = 2, sd = 10) #> 5 draws_3_1 rnorm(mean = 3, sd = 1) #> 6 draws_3_10 rnorm(mean = 3, sd = 10)