karldw
karldw

Reputation: 371

How to iterate over values of a previous target in drake

In drake, I want to take the values of one target and use them in a map to create more targets. In the example below, is there a way to make y2 actually be three targets, as it does for y3? I know it's very different to have the actual values than a target that will be evaluated later, so maybe this is impossible.

x_vals = as.numeric(seq_len(3))

add_1 <- function(x) {
  print(length(x))
  x + 1
}

plan <- drake::drake_plan(
  x1 = x_vals,
  # Runs, as expected, on the whole vector at once
  y1 = add_1(x1),
  # Runs on the whole vector, despite the map()
  y2 = target(add_1(z), transform=map(z=x1)),
  # Makes three separate targets, runs the function on each element
  y3 = target(add_1(z), transform=map(z=!!x_vals))
)
drake::make(plan)
#> target x1
#> target y3_1
#> [1] 1
#> target y3_2
#> [1] 1
#> target y3_3
#> [1] 1
#> target y1
#> [1] 3
#> target y2_x1
#> [1] 3

My question is closely related to this one, but I want to use the new map interface: How to refer to previous targets in drake?

Upvotes: 0

Views: 96

Answers (1)

landau
landau

Reputation: 5841

drake requires that you explicitly declare all your targets in advance before you run make(). So unfortunately, the functionality you propose is not currently available. Many others have requested it, and it is part of drake's future development goals. However, it is the biggest implementation challenge to date, and I have no idea when it will become available. map() and friends may be a step closer.

Upvotes: 1

Related Questions