drake-r-package - 创建目标组

标签 drake-r-package

假设我有以下计划:

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

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

谢谢!

最佳答案

是的,这既可能又简单。内置的解决方案是使用标签: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于2019年11月16日创建(v0.3.0)

关于drake-r-package - 创建目标组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58894812/

相关文章:

r - 多个源顶点的子组件(mode = "in")

r - 跨 R 项目传输对象的最佳实践是什么?

drake-r-package - 从德雷克缓存中删除未使用的和旧的目标

r - 为 Drake 中的所有输入组合生成工作流程计划?

R drake 文件输出带有变量的名称

drake-r-package - 如何引用 drake 中之前的目标?

drake-r-package - Drake 工作流自定义函数单元测试的最佳实践