Skip to content

Instantly share code, notes, and snippets.

@jarad
Last active May 31, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarad/d85a1600e7a3fd83bec1f65fc086b77f to your computer and use it in GitHub Desktop.
Save jarad/d85a1600e7a3fd83bec1f65fc086b77f to your computer and use it in GitHub Desktop.
Script to read a directory of data similar to `read_dir` but using drake to remember what has already been read.
library("drake")
files = list.files("data", "*.csv", full.names = TRUE)
add2 = function(d) { # example function to apply to each individual data.frame
d$x = d$x+2
return(d)
}
plan = drake_plan(
data = target(
read.csv(file_in(file)),
transform = map(file = !!files)
),
add2 = target(
add2(data),
transform = map(data)
),
all = target(
dplyr::bind_rows(add2),
transform = combine(add2)
),
out = saveRDS(all, file = file_out("all.RDS"))
)
plan
make(plan)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment