Is it possible to disable saving command history / session in R by default ? I really hate those .RData and .RHistory files !!
-
Are you using windows/linux/mac? – Dason Apr 11 '12 at 00:27
-
2If you're using a command line interface, I keep the following alias in my .bash_profile: R64='R64 --no-save --no-restore-data --quiet' -- nice and easy. (Similar for R/R32) – mweylandt Apr 11 '12 at 04:47
4 Answers
If you're using RStudio, you can simply disable in settings.
Go to Tools -> Global options -> General and un-tick always save history.

- 1,022
- 1
- 13
- 26
Just start up R with --no-save
. See R --help
.
Add this to your shortcuts (in Windows for example this is under "Target" when you right-click on the shortcut and choose properties).

- 29,099
- 6
- 83
- 91
-
Thanks mdsummer! Any idea how to do this with Notepad++? I tried adding the path to npptor.ini (R=C:\...\bin\x64\Rgui.exe) with and without --no-save, but NppToR seems not to find Rgui. It works if I let it to take it from the registry. – Mikko Apr 11 '12 at 06:33
-
You mean edit a shortcut with a text editor? I don't know anything about Notepad++ – mdsumner Apr 11 '12 at 06:44
-
No. It's an external R script editor, which can be used to send scripts to Rgui. – Mikko Apr 11 '12 at 06:51
-
2Ah, I found solution. Write only the home directory to R Home (R=C:\...\R\R-2.15.0) and the command into R cmd line parameters (Rcmdparms=--no-save --no-restore-data --quiet). Thanks guys! This gave me a smoother R experience. – Mikko Apr 11 '12 at 07:10
-
If you are using an R gui, an alternative and quite nice approach, due to Brian Ripley, (see here), is to put the following lines in your 'R_HOME/etc/Rprofile.site' file:
q <- function (save = "no", status = 0, runLast = TRUE)
.Internal(quit(save, status, runLast))
One note of caution: this won't work when you invoke R from the command-line. In that case, just use the --no-save
argument described in @mdsumner answer.
To learn more about 'Rprofile.site', and '.Rprofile' (an optional per-directory config file), see the always useful ?Startup
help file.

- 159,210
- 26
- 366
- 455
-
I use the R gui and I typically exit with command/Q, which creates aa .Rapp.history. In R preferences I have "Save workspace on exit from R" set to No, but it saves it anyway. – tedtoal Dec 27 '19 at 19:16
-
I tried turning off both "Read history file on startup" and "Save workspace on exit" but that made no difference. Finally I settled on this: I changed the default history file to include "~/" so it places it in my home directory. Then at least I only have the one copy of it. – tedtoal Dec 27 '19 at 19:24
Even more flexible (Windows), add R and RStudio to your right-click menu so you can start in any directory
R-Gui: save the following in a file rguihere.reg, and double-click
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\RGui]
@="R Gui here"
[HKEY_CLASSES_ROOT\Folder\shell\RGui\command]
@="cmd.exe /c \"pushd %L &&start rgui --no-restore --no-save\""
RStudio
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\RStudio]
@="RStudio here"
[HKEY_CLASSES_ROOT\Folder\shell\RStudio\command]
@="cmd.exe /c \"pushd %L &&start C:\\PROGRA~1\\RStudio\\bin\\rstudio.exe\""

- 10,076
- 44
- 67