Scott Coggeshall
Scott Coggeshall

Reputation: 3

Rename target without having to rebuild

Recently after running make() on a drake plan I noticed that I had given the wrong name to one of the targets. Unfortunately this also happened to be one of the targets with a long runtime. Is there a way to rename a target in a drake plan without causing the target to become out of date?

Upvotes: 0

Views: 368

Answers (2)

landau
landau

Reputation: 5841

Edit 2019-07-23

Renaming is now possible in the latest CRAN release (7.5.2). See https://github.com/ropensci/drake/blob/master/README.md#reproducible-data-recovery-and-renaming for details.

Edit 2019-07-18

Actually, there are some circumstances under which renaming can be a good idea. After https://github.com/ropensci/drake/pull/952, drake will support automatic renaming through make(recover = TRUE). However, it will be deactivated by default, and you have to use the same target seeds as last time.

Edit 2019-07-16

Unfortunately, renaming targets in drake is inherently problematic. If you are generating random numbers in a reproducible workflow, please do not try to rename targets.

Why? Because of random number generator (RNG) seeds. Each target's RNG seed is computed deterministically from the target name and the global seed (seed argument of make()). So if you rename the target, you change what the seed should have been, which invalidates the target's value.

Original post

Wait... there actually is a way! See https://github.com/ropensci/drake/issues/935. Just know that targets downstream of renamed targets will most likely be invalidated. Preventing downstream invalidation is the extremely difficult part, and I am not likely to implement it.

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

Created on 2019-07-10 by the reprex package (v0.3.0)

Upvotes: 1

landau
landau

Reputation: 5841

drake has no such functionality right now. It is not impossible, but it would be extremely challenging and complicated to implement. I will think about it, though. It is a neat idea, and I definitely see the utility.

Upvotes: -1

Related Questions