Last active
May 31, 2020 16:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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