Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 349
eaglefreeman Avatar asked Nov 29 '16 09:11

eaglefreeman


People also ask

How do I save my current workspace in R?

Saving the workspace in R is very easy. In case you want to save the full workspace in R, also known as workspace image (those objects that are displayed when you call the ls function), you can use the save. image function. The data will be saved in a file of type RData (also known as rda ).

How do I save and load a workspace in R?

For this, click the File menu and then click save workspace. You will see the dialog box, browse to the folder where you want to save the file and provide the file name of your own choice. Question: How one can access the saved work, while work is saved using save.

Should I save my workspace in R?

You should almost never answer yes. Saving your workspace creates an image of your current variables and functions, and saves them to a file called ”. RData”. When you re-open R from that working directory, the workspace will be loaded, and all these things will be available to you again.


2 Answers

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') 
like image 174
Tim Biegeleisen Avatar answered Sep 20 '22 13:09

Tim Biegeleisen


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") 
like image 34
Garima Gulati Avatar answered Sep 20 '22 13:09

Garima Gulati