This is a follow up for clarification of a previous question, How can I ensure a consistent R environment among different users on the same server?
I’d like to enter a “vanilla” R session from within R, e.g. similar to what I would obtain if I launched R using the command R --vanilla. For example, I would like to write a script that is not confounded by a particular user’s custom settings.
In particular, I’d like the following
- doesn’t read R history, profile, or environment files
- doesn’t reload data or objects from previous sessions
help("vanilla") does not return anything, and I am not familiar enough with the scope of custom settings to know how to get out of all of them.
Is there a way to enter new, vanilla environment? (?new.env does not seem to help)
You can’t just make your current session vanilla, but you can start a fresh vanilla R session from within R like this
I think you’ll probably run into a problem using the above as is because after R restarts, the rest of your script will not execute. With the following code, R will run
.Lastbefore it quits..Lastwill tell it to restart without reading the site file or environment file, and without printing startup messages. Upon restarting, it will run your code (as well as doing some other cleanup).