无需重建即可重命名目标

Rename target without having to rebuild

最近在 运行 make() 之后,我注意到我为其中一个目标指定了错误的名称。不幸的是,这也恰好是运行时间较长的目标之一。有没有办法在不导致目标过时的情况下重命名德雷克计划中的目标?

drake 目前没有这样的功能。这并非不可能,但实施起来将极具挑战性和复杂性。不过,我会考虑的。这是一个绝妙的主意,我绝对看到了实用性。

编辑 2019-07-23

现在可以在最新的 CRAN 版本 (7.5.2) 中重命名。有关详细信息,请参阅 https://github.com/ropensci/drake/blob/master/README.md#reproducible-data-recovery-and-renaming

编辑 2019-07-18

实际上,在某些情况下重命名可能是个好主意。 https://github.com/ropensci/drake/pull/952后,drake将支持通过make(recover = TRUE)自动重命名。不过默认是关闭的,你必须使用和上次一样的目标种子。

编辑 2019-07-16

不幸的是,重命名 drake 中的目标本质上是有问题的。如果您在可重现的工作流程中生成随机数,请不要尝试重命名目标。

为什么?由于随机数生成器 (RNG) 种子。每个目标的 RNG 种子是根据目标名称和全局种子(make()seed 参数)确定性计算的。因此,如果您重命名目标,就会更改种子本应是的内容,这会使目标的值无效。

原版post

等等...实际上一个方法!参见 https://github.com/ropensci/drake/issues/935。只知道重命名目标的下游目标很可能会失效。防止下游失效是极其困难的部分,我不太可能实现。

library(drake)

plan <- drake_plan(
  temp = target(
    matrix(runif(10 ^ 3) + t, ncol = 5),
    transform = map(t = c(2, 5))
  )
)

config <- drake_config(plan)
make(plan)
#> target temp_2
#> target temp_5
outdated(config)
#> character(0)

plan <- drake_plan(
  temp = target(
    matrix(runif(10 ^ 3) + t, ncol = ncol),
    transform = cross(
      ncol = c(5, 2), # Let's switch the order of ncol and t.
      t = c(2, 5)
    )
  )
)

# All 4 targets are out of date because the names are different.
config <- drake_config(plan)

# ncol is the first index.
outdated(config)
#> [1] "temp_2_2" "temp_2_5" "temp_5_2" "temp_5_5"

# Let's rename the original targets.
for (ns in c("objects", "meta")) {
  config$cache$duplicate("temp_2", "temp_5_2", namespace = ns)
  config$cache$duplicate("temp_5", "temp_5_5", namespace = ns)
}

outdated(config)
#> [1] "temp_2_2" "temp_2_5"
make(plan)
#> target temp_2_2
#> target temp_2_5

reprex package (v0.3.0)

于 2019-07-10 创建