drake R - 是否可以通过触发器在功能上生成目标
drake R - Is it possible to functionally generate a target with a trigger
我目前正在评估一个项目drake
,我想知道是否有办法以编程方式生成包含触发器的目标或计划的一部分。
我的理想用途 case/sample 代码如下,但我在尝试使其工作时遇到问题,因为 drake 使用我的函数作为命令,并且不读取触发器。
drake_fetch_remote_data <- function(remote_path, ...) {
hash = retrive_remote_hash(remote_path)
target(
command = fetch_remote_data(remote_path),
trigger = trigger(
change = hash
)
)
}
plan <- drake_plan(
df1 = drake_fetch_remote_data('path1'),
df2 = drake_fetch_remote_data('path2'),
)
#> # A tibble: 2 x 2
#> target command
#> <chr> <expr>
#> 1 df1 drake_fetch_remote_data("path1")
#> 2 df2 drake_fetch_remote_data("path2")
下面的代码包含触发器。
drake_fetch_remote_data <- function(remote_path, ...) {
hash = retrive_remote_hash(remote_path)
target(
command = fetch_remote_data(remote_path),
trigger = trigger(
change = hash
)
)
}
plan <- drake_plan(
df1 = target(
command = fetch_remote_data('path1'),
trigger = trigger(change = lookup_hash('path1'))
)
)
# A tibble: 1 x 3
# target command trigger
# <chr> <expr> <expr>
# 1 df1 fetch_remote_data("path1") trigger(change = lookup_hash("path1"))
当然!有几种方法。请看一下 https://ropenscilabs.github.io/drake-manual/plans.html#large-plans.
library(drake)
# Write out paths one by one.
drake_plan(
df = target(
drake_fetch_remote_data(path),
transform = map(path = c("path1", "path2"))
)
)
#> # A tibble: 2 x 2
#> target command
#> <chr> <expr>
#> 1 df_path1 drake_fetch_remote_data("path1")
#> 2 df_path2 drake_fetch_remote_data("path2")
# Or generate a large collection of paths.
drake_plan(
df = target(
drake_fetch_remote_data(path),
transform = map(path = !!paste0("path", seq_len(10)))
)
)
#> # A tibble: 10 x 2
#> target command
#> <chr> <expr>
#> 1 df_path1 drake_fetch_remote_data("path1")
#> 2 df_path2 drake_fetch_remote_data("path2")
#> 3 df_path3 drake_fetch_remote_data("path3")
#> 4 df_path4 drake_fetch_remote_data("path4")
#> 5 df_path5 drake_fetch_remote_data("path5")
#> 6 df_path6 drake_fetch_remote_data("path6")
#> 7 df_path7 drake_fetch_remote_data("path7")
#> 8 df_path8 drake_fetch_remote_data("path8")
#> 9 df_path9 drake_fetch_remote_data("path9")
#> 10 df_path10 drake_fetch_remote_data("path10")
# You can reference a variable that stores the paths.
paths <- paste0("path", seq_len(10))
drake_plan(
df = target(
drake_fetch_remote_data(path),
transform = map(path = !!paths)
)
)
#> # A tibble: 10 x 2
#> target command
#> <chr> <expr>
#> 1 df_path1 drake_fetch_remote_data("path1")
#> 2 df_path2 drake_fetch_remote_data("path2")
#> 3 df_path3 drake_fetch_remote_data("path3")
#> 4 df_path4 drake_fetch_remote_data("path4")
#> 5 df_path5 drake_fetch_remote_data("path5")
#> 6 df_path6 drake_fetch_remote_data("path6")
#> 7 df_path7 drake_fetch_remote_data("path7")
#> 8 df_path8 drake_fetch_remote_data("path8")
#> 9 df_path9 drake_fetch_remote_data("path9")
#> 10 df_path10 drake_fetch_remote_data("path10")
# Shorter target names.
ids = as.numeric(seq_len(10))
paths <- paste0("path", seq_len(10))
drake_plan(
df = target(
drake_fetch_remote_data(path),
transform = map(path = !!paths, id = !!ids, .id = id)
)
)
#> # A tibble: 10 x 2
#> target command
#> <chr> <expr>
#> 1 df_1 drake_fetch_remote_data("path1")
#> 2 df_2 drake_fetch_remote_data("path2")
#> 3 df_3 drake_fetch_remote_data("path3")
#> 4 df_4 drake_fetch_remote_data("path4")
#> 5 df_5 drake_fetch_remote_data("path5")
#> 6 df_6 drake_fetch_remote_data("path6")
#> 7 df_7 drake_fetch_remote_data("path7")
#> 8 df_8 drake_fetch_remote_data("path8")
#> 9 df_9 drake_fetch_remote_data("path9")
#> 10 df_10 drake_fetch_remote_data("path10")
由 reprex package (v0.2.1)
于 2019-05-03 创建
编辑 2019-05-05
触发器可以像命令一样使用分组变量。
library(drake)
ids <- as.numeric(seq_len(10))
paths <- paste0("path", seq_len(10))
drake_plan(
df = target(
fetch_data(path),
trigger = trigger(change = hash_data(path)),
transform = map(path = !!paths, id = !!ids, .id = id)
)
)
#> # A tibble: 10 x 3
#> target command trigger
#> <chr> <expr> <expr>
#> 1 df_1 fetch_data("path1") trigger(change = hash_data("path1"))
#> 2 df_2 fetch_data("path2") trigger(change = hash_data("path2"))
#> 3 df_3 fetch_data("path3") trigger(change = hash_data("path3"))
#> 4 df_4 fetch_data("path4") trigger(change = hash_data("path4"))
#> 5 df_5 fetch_data("path5") trigger(change = hash_data("path5"))
#> 6 df_6 fetch_data("path6") trigger(change = hash_data("path6"))
#> 7 df_7 fetch_data("path7") trigger(change = hash_data("path7"))
#> 8 df_8 fetch_data("path8") trigger(change = hash_data("path8"))
#> 9 df_9 fetch_data("path9") trigger(change = hash_data("path9"))
#> 10 df_10 fetch_data("path10") trigger(change = hash_data("path10"))
由 reprex package (v0.2.1)
于 2019-05-06 创建
为了更清楚,您还可以将命令作为命名参数提供给 target()
。
library(drake)
ids <- as.numeric(seq_len(10))
paths <- paste0("path", seq_len(10))
drake_plan(
df = target(
command = fetch_data(path), # now named for clarity
trigger = trigger(change = hash_data(path)),
transform = map(path = !!paths, id = !!ids, .id = id)
)
)
#> # A tibble: 10 x 3
#> target command trigger
#> <chr> <expr> <expr>
#> 1 df_1 fetch_data("path1") trigger(change = hash_data("path1"))
#> 2 df_2 fetch_data("path2") trigger(change = hash_data("path2"))
#> 3 df_3 fetch_data("path3") trigger(change = hash_data("path3"))
#> 4 df_4 fetch_data("path4") trigger(change = hash_data("path4"))
#> 5 df_5 fetch_data("path5") trigger(change = hash_data("path5"))
#> 6 df_6 fetch_data("path6") trigger(change = hash_data("path6"))
#> 7 df_7 fetch_data("path7") trigger(change = hash_data("path7"))
#> 8 df_8 fetch_data("path8") trigger(change = hash_data("path8"))
#> 9 df_9 fetch_data("path9") trigger(change = hash_data("path9"))
#> 10 df_10 fetch_data("path10") trigger(change = hash_data("path10"))
由 reprex package (v0.2.1)
于 2019-05-06 创建
我目前正在评估一个项目drake
,我想知道是否有办法以编程方式生成包含触发器的目标或计划的一部分。
我的理想用途 case/sample 代码如下,但我在尝试使其工作时遇到问题,因为 drake 使用我的函数作为命令,并且不读取触发器。
drake_fetch_remote_data <- function(remote_path, ...) {
hash = retrive_remote_hash(remote_path)
target(
command = fetch_remote_data(remote_path),
trigger = trigger(
change = hash
)
)
}
plan <- drake_plan(
df1 = drake_fetch_remote_data('path1'),
df2 = drake_fetch_remote_data('path2'),
)
#> # A tibble: 2 x 2
#> target command
#> <chr> <expr>
#> 1 df1 drake_fetch_remote_data("path1")
#> 2 df2 drake_fetch_remote_data("path2")
下面的代码包含触发器。
drake_fetch_remote_data <- function(remote_path, ...) {
hash = retrive_remote_hash(remote_path)
target(
command = fetch_remote_data(remote_path),
trigger = trigger(
change = hash
)
)
}
plan <- drake_plan(
df1 = target(
command = fetch_remote_data('path1'),
trigger = trigger(change = lookup_hash('path1'))
)
)
# A tibble: 1 x 3
# target command trigger
# <chr> <expr> <expr>
# 1 df1 fetch_remote_data("path1") trigger(change = lookup_hash("path1"))
当然!有几种方法。请看一下 https://ropenscilabs.github.io/drake-manual/plans.html#large-plans.
library(drake)
# Write out paths one by one.
drake_plan(
df = target(
drake_fetch_remote_data(path),
transform = map(path = c("path1", "path2"))
)
)
#> # A tibble: 2 x 2
#> target command
#> <chr> <expr>
#> 1 df_path1 drake_fetch_remote_data("path1")
#> 2 df_path2 drake_fetch_remote_data("path2")
# Or generate a large collection of paths.
drake_plan(
df = target(
drake_fetch_remote_data(path),
transform = map(path = !!paste0("path", seq_len(10)))
)
)
#> # A tibble: 10 x 2
#> target command
#> <chr> <expr>
#> 1 df_path1 drake_fetch_remote_data("path1")
#> 2 df_path2 drake_fetch_remote_data("path2")
#> 3 df_path3 drake_fetch_remote_data("path3")
#> 4 df_path4 drake_fetch_remote_data("path4")
#> 5 df_path5 drake_fetch_remote_data("path5")
#> 6 df_path6 drake_fetch_remote_data("path6")
#> 7 df_path7 drake_fetch_remote_data("path7")
#> 8 df_path8 drake_fetch_remote_data("path8")
#> 9 df_path9 drake_fetch_remote_data("path9")
#> 10 df_path10 drake_fetch_remote_data("path10")
# You can reference a variable that stores the paths.
paths <- paste0("path", seq_len(10))
drake_plan(
df = target(
drake_fetch_remote_data(path),
transform = map(path = !!paths)
)
)
#> # A tibble: 10 x 2
#> target command
#> <chr> <expr>
#> 1 df_path1 drake_fetch_remote_data("path1")
#> 2 df_path2 drake_fetch_remote_data("path2")
#> 3 df_path3 drake_fetch_remote_data("path3")
#> 4 df_path4 drake_fetch_remote_data("path4")
#> 5 df_path5 drake_fetch_remote_data("path5")
#> 6 df_path6 drake_fetch_remote_data("path6")
#> 7 df_path7 drake_fetch_remote_data("path7")
#> 8 df_path8 drake_fetch_remote_data("path8")
#> 9 df_path9 drake_fetch_remote_data("path9")
#> 10 df_path10 drake_fetch_remote_data("path10")
# Shorter target names.
ids = as.numeric(seq_len(10))
paths <- paste0("path", seq_len(10))
drake_plan(
df = target(
drake_fetch_remote_data(path),
transform = map(path = !!paths, id = !!ids, .id = id)
)
)
#> # A tibble: 10 x 2
#> target command
#> <chr> <expr>
#> 1 df_1 drake_fetch_remote_data("path1")
#> 2 df_2 drake_fetch_remote_data("path2")
#> 3 df_3 drake_fetch_remote_data("path3")
#> 4 df_4 drake_fetch_remote_data("path4")
#> 5 df_5 drake_fetch_remote_data("path5")
#> 6 df_6 drake_fetch_remote_data("path6")
#> 7 df_7 drake_fetch_remote_data("path7")
#> 8 df_8 drake_fetch_remote_data("path8")
#> 9 df_9 drake_fetch_remote_data("path9")
#> 10 df_10 drake_fetch_remote_data("path10")
由 reprex package (v0.2.1)
于 2019-05-03 创建编辑 2019-05-05
触发器可以像命令一样使用分组变量。
library(drake)
ids <- as.numeric(seq_len(10))
paths <- paste0("path", seq_len(10))
drake_plan(
df = target(
fetch_data(path),
trigger = trigger(change = hash_data(path)),
transform = map(path = !!paths, id = !!ids, .id = id)
)
)
#> # A tibble: 10 x 3
#> target command trigger
#> <chr> <expr> <expr>
#> 1 df_1 fetch_data("path1") trigger(change = hash_data("path1"))
#> 2 df_2 fetch_data("path2") trigger(change = hash_data("path2"))
#> 3 df_3 fetch_data("path3") trigger(change = hash_data("path3"))
#> 4 df_4 fetch_data("path4") trigger(change = hash_data("path4"))
#> 5 df_5 fetch_data("path5") trigger(change = hash_data("path5"))
#> 6 df_6 fetch_data("path6") trigger(change = hash_data("path6"))
#> 7 df_7 fetch_data("path7") trigger(change = hash_data("path7"))
#> 8 df_8 fetch_data("path8") trigger(change = hash_data("path8"))
#> 9 df_9 fetch_data("path9") trigger(change = hash_data("path9"))
#> 10 df_10 fetch_data("path10") trigger(change = hash_data("path10"))
由 reprex package (v0.2.1)
于 2019-05-06 创建为了更清楚,您还可以将命令作为命名参数提供给 target()
。
library(drake)
ids <- as.numeric(seq_len(10))
paths <- paste0("path", seq_len(10))
drake_plan(
df = target(
command = fetch_data(path), # now named for clarity
trigger = trigger(change = hash_data(path)),
transform = map(path = !!paths, id = !!ids, .id = id)
)
)
#> # A tibble: 10 x 3
#> target command trigger
#> <chr> <expr> <expr>
#> 1 df_1 fetch_data("path1") trigger(change = hash_data("path1"))
#> 2 df_2 fetch_data("path2") trigger(change = hash_data("path2"))
#> 3 df_3 fetch_data("path3") trigger(change = hash_data("path3"))
#> 4 df_4 fetch_data("path4") trigger(change = hash_data("path4"))
#> 5 df_5 fetch_data("path5") trigger(change = hash_data("path5"))
#> 6 df_6 fetch_data("path6") trigger(change = hash_data("path6"))
#> 7 df_7 fetch_data("path7") trigger(change = hash_data("path7"))
#> 8 df_8 fetch_data("path8") trigger(change = hash_data("path8"))
#> 9 df_9 fetch_data("path9") trigger(change = hash_data("path9"))
#> 10 df_10 fetch_data("path10") trigger(change = hash_data("path10"))
由 reprex package (v0.2.1)
于 2019-05-06 创建