Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Rhistory file not loaded at startup

Tags:

r

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

like image 915
gabx Avatar asked Oct 25 '13 12:10

gabx


People also ask

How do you stop Rhistory?

Go to Tools -> Global options -> General and un-tick always save history. Save this answer.

How do you save a history file in R?

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


2 Answers

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.

like image 183
not2qubit Avatar answered Nov 10 '22 20:11

not2qubit


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
like image 35
gabx Avatar answered Nov 10 '22 20:11

gabx