I have several data.frames
in an environment which I would like to save into separate .RData files. Is there a function which is able to save to whole workspace?
I usually just do this with the following function:
save(x, file = "xy.RData")
but is there a way I could save all the data.frames separately at once?
Creating a bunch of different files isn't how save()
is vectorized. Probably better to use a loop here. First, get a vector of all of your data.frame names.
dfs<-Filter(function(x) is.data.frame(get(x)) , ls())
Now write each to a file.
for(d in dfs) {
save(list=d, file=paste0(d, ".RData"))
}
Or if you just wanted them all in one file
save(list=dfs, file="alldfs.RData")
To save your workspace you just need to do:
save.image("willcontainworkspace.RData")
This creates a single file that contains the entire workspace which may or may not be what you want but your question wasn't completely clear to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With