【发布时间】:2020-09-24 17:01:56
【问题描述】:
我在我的德雷克计划中创建了一组文件。我想将这些文件的一个子集复制到另一个位置。
以下代码几乎可以实现这一点。但是,在获取我要复制的文件目标的子集后,drake 对文件更改的依赖关系跟踪丢失了。
如何在不丢失 drake 依赖跟踪的情况下合并/子集动态文件目标?
copy_file <- function(file) {
file_copy <- paste0(file, "_copy")
file.copy(from = file, to = file_copy, overwrite = TRUE)
file_copy
}
herb_1_a <- "parsley"
plan <- drake::drake_plan(
file_1 = target(
{
writeLines(herb_1_a, "file_1_a") # Second run
writeLines("sage", "file_1_b")
c("file_1_a", "file_1_b")
},
format = "file"
),
file_2 = target(
{
writeLines("rosemary", "file_2_a")
writeLines("thyme", "file_2_b")
c("file_2_a", "file_2_b")
},
format = "file"
),
files_to_copy = str_subset(
c(file_1, file_2),
"_a$"
),
file_copies = target(
copy_file(files_to_copy),
dynamic = map(files_to_copy),
format = "file"
)
)
drake::make(plan)
#> ▶ target file_2
#> ▶ target file_1
#> ▶ target files_to_copy
#> ▶ dynamic file_copies
#> > subtarget file_copies_5e57e9ee
#> > subtarget file_copies_ae26ecf9
#> ■ finalize file_copies
readLines("file_1_a")
#> [1] "parsley"
readLines("file_1_a_copy")
#> [1] "parsley"
herb_1_a <- 'banana'
drake::make(plan)
#> ▶ target file_1
#> ▶ target files_to_copy
readLines("file_1_a")
#> [1] "banana"
readLines("file_1_a_copy") # I want this banana
#> [1] "parsley"
由reprex package (v0.3.0) 于 2020 年 9 月 24 日创建
【问题讨论】:
标签: r drake-r-package