Reputation: 854
I want to save an image of the workspace in the .RData file but without exiting the current session. Something like q('yes')
but without quitting.
Upvotes: 28
Views: 42189
Reputation: 11192
The session
https://www.rdocumentation.org/packages/session/versions/1.0.3 package allows to save/load both objects and also loaded packages. Although it was removed from CRAN some time ago, it is still functional (R v4.1) and can be installed from the archive easily
install.packages("https://cran.r-project.org/src/contrib/Archive/session/session_1.0.3.tar.gz")
To use it, do
session::save.session(".mysession.dat")
session::restore.session(".mysession.dat")
This often works much better save.image
because, without packages, the session information tends to be too incomplete to be useful.
Upvotes: 0
Reputation: 43
Apart from save.image()
function, that lets you save the entire workspace, you can also check the save()
function.
save()
function lets you save individual objects in the workspace.
save(ObjectToBeSaved, file = "FileName.RData")
Upvotes: 3
Reputation: 521467
You can use save.image()
at any time to save all environment data into an .RData
file:
save.image(file='yoursession.RData')
To load this data later you can use:
load('yoursession.RData')
Upvotes: 50