如何迭代德雷克中先前目标的值

How to iterate over values of a previous target in drake

在 drake 中,我想获取一个目标的 并在 map 中使用它们来创建更多目标。在下面的示例中,是否有办法使 y2 实际上成为三个目标,就像 y3 那样?我知道实际值与稍后将评估的目标有很大不同,所以这可能是不可能的。

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

我的问题与这个问题密切相关,但我想使用新的 map 界面:

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。然而,这是迄今为止最大的实施挑战,我不知道它何时可用。 map()和朋友可能更近一步