2

my_function(x, y)入力のすべての組み合わせに対して何らかの機能を実行するワークフロー プランを作成しようとしていますmy_datasetが、貼り付けを使用せずにドレイクのワークフローのコマンドを生成する方法に行き詰まっています。

検討:

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)

出力:

> 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)

上記のコードは機能しますが、paste0 を使用して関数呼び出しを生成しています。これは最適ではないと思いますし、スケーリングも不十分です。これらの計画を生成するより良い方法はありますか? これはドレイクの質問ではなく、むしろ質問かもしれませんrlang

4

2 に答える 2