Can I prevent R from creating .RData files?

Viewed 39

I am trying to share some R code with colleagues who don't know R. I have created a batch file so they can just double-click it and run the R script without even opening R. But it creates a .RData file.

My question is, can I prevent R from creating the .RData file?

I've read here Disable saving history that I could disable it through RStudio global options but my colleagues are installing just R and won't need to ever open it, so I am looking for some kind of solution of the likes of options(...) that I can just put in my Rscript, or maybe something that could be speficied in the batch file call.

1 Answers

For anyone curious, I figured it out thanks to @r2evans and this post: https://es.stackoverflow.com/questions/166211/evitar-que-r-cree-ficheros-r-data-y-r-history.

I just had to add --no-save to my batch call like this:

R CMD BATCH --no-save "%file%" NUL

where %file% is the Rscript path. The NUL part is so a .Rout file won't be created after running the batch file.

Also, doing

Rscript.exe "%file%" 

runs the Rscript and doesn't produce .RData or .Rout files. The difference is that R messages get printed on the command window as they would in an interactive R session.

Related