我可以想到几种不同的方式rlang::syms()
在drake_plan()
. 第一:
library(drake)
library(rlang)
functions <- syms(paste0("f", seq_len(4)))
index <- as.numeric(seq_len(4))
inputs <- syms(paste0("x_", index - 1))
plan <- drake_plan(
x = target(
f(x, param = "some param"),
transform = map(f = !!functions, x = !!inputs, id = !!index, .id = id)
)
)
plan
#> # A tibble: 4 x 2
#> target command
#> <chr> <expr>
#> 1 x_1 f1(x_0, param = "some param")
#> 2 x_2 f2(x_1, param = "some param")
#> 3 x_3 f3(x_2, param = "some param")
#> 4 x_4 f4(x_3, param = "some param")
config <- drake_config(plan)
vis_drake_graph(config)
由reprex 包(v0.3.0)于 2019 年 9 月 27 日创建
第二个:
library(drake)
library(rlang)
library(tibble)
f <- syms(paste0("f", seq_len(4)))
index <- as.numeric(seq_len(4))
inputs <- syms(paste0("x_", index - 1))
grid <- tibble(
f = f,
index = index,
inputs = inputs
)
plan <- drake_plan(
x = target(
f(inputs, param = "some param"),
transform = map(.data = !!grid, .id = index)
)
)
plan
#> # A tibble: 4 x 2
#> target command
#> <chr> <expr>
#> 1 x_1 f1(x_0, param = "some param")
#> 2 x_2 f2(x_1, param = "some param")
#> 3 x_3 f3(x_2, param = "some param")
#> 4 x_4 f4(x_3, param = "some param")
config <- drake_config(plan)
vis_drake_graph(config)
由reprex 包(v0.3.0)于 2019 年 9 月 27 日创建