R/generate.R
Creates a new workflow plan data frame with the commands to do a reduction (i.e. to repeatedly apply a binary operator to pairs of targets to produce one target).
reduce_plan(plan = NULL, target = "target", begin = "", op = " + ", end = "", pairwise = TRUE)
plan | workflow plan data frame of prespecified targets |
---|---|
target | name of the new reduced target |
begin | character, code to place at the beginning of each step in the reduction |
op | binary operator to apply in the reduction |
end | character, code to place at the end of each step in the reduction |
pairwise | logical, whether to create multiple
new targets, one for each pair/step in the reduction ( |
A workflow plan data frame that aggregates multiple prespecified targets into one additional target downstream.
# Workflow plan for datasets: x_plan <- evaluate_plan( drake_plan(x = VALUE), wildcard = "VALUE", values = 1:8 ) # Create a new target from the sum of the others. reduce_plan(x_plan, target = "x_sum", pairwise = FALSE)#> # A tibble: 1 x 2 #> target command #> <chr> <chr> #> 1 x_sum x_1 + x_2 + x_3 + x_4 + x_5 + x_6 + x_7 + x_8# For memory efficiency and parallel computing, # reduce pairwise: reduce_plan(x_plan, target = "x_sum", pairwise = TRUE)#> # A tibble: 7 x 2 #> target command #> <chr> <chr> #> 1 x_sum_1 x_1 + x_2 #> 2 x_sum_2 x_3 + x_4 #> 3 x_sum_3 x_5 + x_6 #> 4 x_sum_4 x_7 + x_8 #> 5 x_sum_5 x_sum_1 + x_sum_2 #> 6 x_sum_6 x_sum_3 + x_sum_4 #> 7 x_sum x_sum_5 + x_sum_6# Optionally define your own function and use it as the # binary operator in the reduction. x_plan <- evaluate_plan( drake_plan(x = VALUE), wildcard = "VALUE", values = 1:9 ) x_plan#> # A tibble: 9 x 2 #> target command #> <chr> <chr> #> 1 x_1 1 #> 2 x_2 2 #> 3 x_3 3 #> 4 x_4 4 #> 5 x_5 5 #> 6 x_6 6 #> 7 x_7 7 #> 8 x_8 8 #> 9 x_9 9reduce_plan( x_plan, target = "x_sum", pairwise = TRUE, begin = "fun(", op = ", ", end = ")" )#> # A tibble: 8 x 2 #> target command #> <chr> <chr> #> 1 x_sum_1 fun(x_1, x_2) #> 2 x_sum_2 fun(x_3, x_4) #> 3 x_sum_3 fun(x_5, x_6) #> 4 x_sum_4 fun(x_7, x_8) #> 5 x_sum_5 fun(x_9, x_sum_1) #> 6 x_sum_6 fun(x_sum_2, x_sum_3) #> 7 x_sum_7 fun(x_sum_4, x_sum_5) #> 8 x_sum fun(x_sum_6, x_sum_7)