Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable "Save workspace image?" prompt in R?

When I exit the interactive R shell, it displays an annoying prompt every time:

 > > Save workspace image? [y/n/c]: n 

I'm always answering "no" to it, because if I wished to save my work, I'd do that before trying to exit.

How to get rid of the prompt?


Note: see ?save.image

like image 486
ulidtko Avatar asked Feb 14 '11 18:02

ulidtko


People also ask

Should I save my workspace image in R?

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. But you don't want that, so don't save your workspace.

What is workspace image in R?

The workspace is your current R working environment and includes any user-defined objects (vectors, matrices, data frames, lists, functions). At the end of an R session, the user can save an image of the current workspace that is automatically reloaded the next time R is started.

What is saving 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 ).


2 Answers

You can pass the --no-save command line argument when you start R, or you can override the q function:

utils::assignInNamespace(   "q",    function(save = "no", status = 0, runLast = TRUE)    {     .Internal(quit(save, status, runLast))   },    "base" ) 

Put the above code in your .Rprofile so it will be run on startup for every session.

like image 68
Joshua Ulrich Avatar answered Sep 22 '22 12:09

Joshua Ulrich


Haven't found the easiest Linux solution yet :)

On ubuntu add the following line to your ~/.bashrc:

alias R='R --no-save' 

Every time you start the R console with R, it will be passed the --no-save option.

like image 28
mreq Avatar answered Sep 24 '22 12:09

mreq