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
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.
Get the best of both strategies given by users 1 and 2:
Default to not save by adding the following line to your ~/.bashrc:
alias R='R --no-save'
But give yourself an easy way to save on exit by adding this to ~/.Rprofile:
qs <- function(save="yes") { q(save=save)}
So now q()
will quit without saving or prompting but qs()
will save and quit (also without prompting)
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.
You can escape the "Save workspace image?" prompt with a Ctrl+D.
Thus, if you do Ctrl+D twice in interactive R, then you exit R without saving your workspace.
(Tested on Linux and OS X)
If, like me, typing out a whole pair of brackets seems like too much effort to exit the repl you can try this:
exit <- structure(list(), class = "exit_command")
print.exit_command <- function(...) {
q("no") # exit without saving
}
This creates a new class, which causes R to exit when attempting to print said class. The upshot being that if you run exit
in the R repl, the whole thing will exit (because it tries to print it).
NB: You can add it to ~/.Rprofile
to load at the start of every session.
You could easily add a qq()
function to the .Rprofile file
qq <- function(save="no") { q(save=save)}
I thought that the save option was available with options, but apparently Joshua's answer is best.