I would like to save data to
.rda files in
My approach is to first set up a loop that sources R files in
/data-raw while saving the result to an environment. Then I would like to save every object in the environment to and
.rda file in
save(), each object needs to be specified passed using its bare-unquoted name. I like to think there is a way around this using
eapply(), but I am unfamiliar with looping through environments.
My work so far:
# General workflow # All external data are read/tidied in files preceded with "external", # and they only return that single object (one per file). # This how I would like to create and save my external data. external_files <- list.files("data-raw", pattern = "^external", full.names = TRUE) external_env <- new.env() lapply(external_files, source, local = external_env) # Now for the hard part. # For reproducibility I'll add something to external_env external_env$a <- letters external_env$i <- iris eapply(external_env, function(x) assign(x, x, pos = .GlobalEnv)) #> Error in assign(x, x, pos = .GlobalEnv) : invalid first argument
a is saved into the global environment. Data.frames/lists seem like they are unable to be saved.