我想使用德雷克的动态目标来读取多个文件。我根据对动态文件工作原理的理解编写了以下计划。但是,当输入文件更改时,drake 不会正确更新所有目标。
使用drake的动态文件读取文件的正确方法是什么?
换句话说,file_in()
解决这个问题的动态文件版本是什么:How can I import from multiple files in r-drake?
library(drake)
library(tidyverse)
content <- tibble(x1 = 1, x2 = 1)
walk(list("a", "b"), ~ write_csv(x = content, path = paste0(., ".csv")))
read_csv("b.csv", col_types = "dd")
#> # A tibble: 1 x 2
#> x1 x2
#> <dbl> <dbl>
#> 1 1 1
plan <- drake::drake_plan(
import_paths = target(c(
a = "a.csv",
b = "b.csv"
),
format = "file"
),
data = target(
read_csv(import_paths, col_types = "dd"),
dynamic = map(import_paths)
)
)
drake::make(plan)
#> ▶ target import_paths
#> ▶ dynamic data
#> > subtarget data_44119303
#> > subtarget data_ecc6ebe6
#> ■ finalize data
readd(data)
#> # A tibble: 2 x 2
#> x1 x2
#> <dbl> <dbl>
#> 1 1 1
#> 2 1 1
walk(list("b"), ~ write_csv(x = content + 1, path = paste0(., ".csv")))
read_csv("b.csv", col_types = "dd")
#> # A tibble: 1 x 2
#> x1 x2
#> <dbl> <dbl>
#> 1 2 2
drake::make(plan)
#> ▶ target import_paths
#> ■ finalize data
readd(data)
#> # A tibble: 2 x 2
#> x1 x2
#> <dbl> <dbl>
#> 1 1 1
#> 2 1 1
由reprex 包(v0.3.0)于 2020-08-06 创建