eaglefreeman
eaglefreeman

Reputation: 854

In R, is it possible to save the current workspace without quitting?

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

Answers (3)

Holger Brandl
Holger Brandl

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

Garima Gulati
Garima Gulati

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

Tim Biegeleisen
Tim Biegeleisen

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

Related Questions