Disable saving history
Asked Answered
K

4

29

Is it possible to disable saving command history / session in R by default ? I really hate those .RData and .RHistory files !!

Kurtzman answered 11/4, 2012 at 0:7 Comment(2)
Are you using windows/linux/mac?Saharanpur
If 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)Arrowood
U
16

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

enter image description here

Updo answered 11/4, 2012 at 0:11 Comment(5)
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.Jillayne
You mean edit a shortcut with a text editor? I don't know anything about Notepad++Updo
No. It's an external R script editor, which can be used to send scripts to Rgui.Jillayne
Ah, 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.Jillayne
No, see Project Options under GeneralUpdo
D
25

If you're using RStudio, you can simply disable in settings.

Go to Tools -> Global options -> General and un-tick always save history. enter image description here

Dill answered 28/12, 2018 at 8:11 Comment(0)
U
16

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

enter image description here

Updo answered 11/4, 2012 at 0:11 Comment(5)
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.Jillayne
You mean edit a shortcut with a text editor? I don't know anything about Notepad++Updo
No. It's an external R script editor, which can be used to send scripts to Rgui.Jillayne
Ah, 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.Jillayne
No, see Project Options under GeneralUpdo
H
7

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.

Helical answered 11/4, 2012 at 7:8 Comment(2)
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.Legato
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.Legato
A
1

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\""
Astraphobia answered 11/4, 2012 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.