Here is how I start R on my linux machine.
.Rprofile is at the root of my $HOME directory and has only this line:
source ("~/.config/r/Renviron.r")
Then I append all kind of options,user environment variable paths,functions or aliases in my Renviron.r file. Among other lines, this one set the path to Rhistory :
Sys.setenv(R_HISTFILE="/developement/language/r/.Rhistory")
The path is correct, as returned by command
R > Sys.getenv("R_HISTFILE")
Following this documentation, it seems there is no need to tell R explicitly to load history (loadhistory("path/to/HISTFILE"). When I run R on my terminal, there is no history.
What am I doing wrong ? Thank you for help
Go to Tools -> Global options -> General and un-tick always save history. Save this answer.
You can save the entire history of commands using the command savehistory(). By default, these commands are saved to the default file, ". Rhistory", but you can set your own. You can also load a saved history with loadhistory().
For some reason the R documentation on how to load the history is not updated or correct. Apparently the only way to get it to work is by using the utils::
hook for the library that contain the loadhistory()
function. In your .Rprofile
, add the line like this:
if(interactive()) try(utils::loadhistory(file="C:/pathto/home/xxxx/.Rhistory"))
Trying to load this without the hook, results in a "function not found" error.
I found the reason why I couldn't load my HISTFILE.This file had to be renamed with at least one letter before .Rhistory.
> loadhistory("path/to/.Rhistory") # loads no commands
> loadhistory("path/to/R.Rhistory") # loads indeed command history
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With