I want to import data of a similar category from multiple source files.
Every source has a short label.
How can I incorporate this into drake, without writing out every file as its own target?
I thought the following would work, but it does not. Ideally, I would like to have the targets raw_a
and raw_b
.
input_files <- list(
'a' = 'file_1.csv',
'b' = 'file_2.csv'
)
plan <-
drake::drake_plan(
raw = drake::target(
import_file(file),
transform = map(
file = file_in(!! input_files)
)
)
)
with
import_file <- function(file) {
readr::read_csv(file, skip = 2)
}
You are so close. file_in()
needs to go literally in the command, not the transformation.
library(drake)
input_files <- c("file_1.csv", "file_2.csv")
plan <- drake_plan(
raw = target(
import_file(file_in(file)),
transform = map(file = !!input_files)
)
)
config <- drake_config(plan)
vis_drake_graph(config)
Created on 2019-10-19 by the reprex package (v0.3.0)