I'm trying to create a workflow plan that will run some function my_function(x, y)
for all combination of inputs in my_dataset
but am stuck as to how to to generate the commands for drake's workflow without using paste.
Consider:
library(drake)
library(dplyr)
A <- 'apple'
B <- 'banana'
C <- 'carrot'
my_function <- function(x, y)
paste(x, y, sep='|IT WORKS|')
my_function(A, B)
combos <- combn(c('A', 'B', 'C'), 2) %>%
t() %>%
as_data_frame()
targets <- apply(combos, 1, paste, collapse = '_')
commands <- paste0('my_function(', apply(combos, 1, paste, collapse = ', '), ')')
my_plan <- data_frame(target = targets, command = commands)
make(my_plan)
Output:
> my_plan
# A tibble: 3 x 2
target command
<chr> <chr>
1 A_B my_function(A, B)
2 A_C my_function(A, C)
3 B_C my_function(B, C)
The above code works, but I am using paste0 to generate the function call. I don't think this is optimal and it scales poorly. Is there a better way to generate these plans? This may be less of a drake question and more of an rlang
question.