2

假设我有以下计划:

test_plan = drake_plan(
    foo = target(x + 1, transform = map(x = c(5, 10))),
    bar = 42
)

现在我想创建一个包含两个子目标 foo_5、foo_10 和目标 bar 的新目标。我怎样才能做到这一点?我觉得它一定非常简单,但我无法找到解决方案。

谢谢!

4

1 回答 1

2

是的,这既可行又简单。内置解决方案是使用标签:https ://books.ropensci.org/drake/static.html#tags 。例子:

library(drake)
drake_plan(
  foo = target(
    x + 1,
    transform = map(x = c(5, 10), .tag_out = group)
  ),
  bar = target(
    42,
    # You need a transform to use a tag, even for 1 target.
    transform = map(tmp = 1, .tag_out = group)
  ),
  baz_map = target(group, transform = map(group)),
  baz_combine = target(c(group), transform = combine(group))
)
#> # A tibble: 7 x 2
#>   target         command                
#>   <chr>          <expr>                 
#> 1 foo_5          5 + 1                  
#> 2 foo_10         10 + 1                 
#> 3 bar_1          42                     
#> 4 baz_map_foo_5  foo_5                  
#> 5 baz_map_foo_10 foo_10                 
#> 6 baz_map_bar_1  bar_1                  
#> 7 baz_combine    c(foo_5, foo_10, bar_1)

reprex 包(v0.3.0)于 2019 年 11 月 16 日创建

于 2019-11-16T20:29:25.320 回答