How to Disable "Save Workspace Image" Prompt in R

How to disable Save workspace image? prompt in R?

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.

Saving workspace image, in R


What does that mean?

It means that R saves a list of objects in your global environment (i.e. where your normal work happens) into a file. When R next loads, this list is by default restored (at least partially — there are cases where it won’t work).

A consequence is that restarting R does not give you a clean slate. Instead, your workspace is cluttered with existing stuff, which is generally not what you want. People then resort to all kinds of hacks to try to clean their workspace. But none of these hacks are reliable, and none are necessary if you simply don’t save/restore your workspace.

If I choose to save the workspace image, where is it saved?

R creates a (hidden) file called .RData in your current working directory.

I always choose not to save the workspace image, are there any disadvantages to save it?

The advantage is that, under some circumstances, you avoid recomputing results when you continue your work later. However, there are other, better ways of achieving this. On the flip side, starting R without a clean slate has many disadvantages: Any new analysis you now start won’t be in a clean room, and it won’t be reproducible when executed again.

So you are doing the right thing by not saving the workspace! It’s one of the rules of creating reproducible R code. For more information, I recommend Jenny Bryan’s article on using R with a Project-oriented workflow

But having to manually reject saving the workspace every time is annoying and error-prone. You can disable the dialog box in the RStudio options.

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

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')

When I try to clear the workspace in R console, it always asks through a pop-up. How can I disable the pop-up?

There are some suggestions (here) depending on your platform. Looks like passing the "no-save" option when invoking R is your best bet: https://stackoverflow.com/a/4996252/8273813

How to make q('yes') the default quitting behavior in R using .Rprofile?

In your Rprofile.site file:

q <- function(save = "yes", status = 0, runLast = TRUE){
.Internal(quit(save, status, runLast))
#<environment: namespace:base>
}

How to disable source() file echo in R?

How about

library(Defaults)
setDefaults("source",echo=FALSE)

?

This is similar to (but not quite identical/somewhat simpler than) the answer to this question.

Since the Defaults package was archived 6 months after this question was answered, you either would have to get it from here or use devtools::install_version("Defaults","1.1-1"), or fall back to @KonradRudolph's answer.

Saving and Reloading an R workspace image in Eclipse StatET

The default "savename" should be something like .Rdata or .Rda and it will go to your current working directory. If you are on a Mac or Windows device the default may be to hide such files from "visibility" from your system file browser, although you should be able to use file.choose() in any place where you would be specifying a file name. I don't understand how you "save a workspace image" that cannot be load()-ed unless what your really mean is cannot be found. See if you can find it with:

load(file.choose() )

To get better answers you should include information about your OS and the code you are having problems with.

How can I integrate the Export -- Save as Image Click Process into a script?

Here is an attempt to answer your question. I tested your code and at least it works on Ubuntu 18.04.

# your code up

# create the file
png(filename = "test.png", width = 480, height = 480, units = "px", pointsize = 12, bg = "white", res = NA, type = c("cairo", "cairo-png", "Xlib", "quartz"))
# plot
with(dat, plot(x,y, type="l", xlim =c(-2,2), ylim =c(-2,2), xlab = "", ylab = "", xaxt='n', yaxt='n'))
# close the file
dev.off()


Related Topics



Leave a reply



Submit