创建目标组

Create groups of targets

假设我有以下计划:

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

现在我想创建一个包含两个子目标 foo_5、foo_10 和目标栏的新目标。我怎样才能做到这一点?感觉一定超级简单,就是没找到解决办法

谢谢!

是的,既可行又简单。内置的解决方案是使用标签: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 package (v0.3.0)

创建于 2019-11-16