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?