Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R sometimes does not save my history

Tags:

r

I have a program in R. Sometimes when I save history, they do not write into my history file. I lost some histories a few times and this really drive me crazy.

Any recommendation on how to avoid this?

like image 369
Lily Avatar asked Apr 11 '11 23:04

Lily


People also ask

Does R save history?

R. app , the console on macOS, has a separate and largely incompatible history mechanism, which by default uses a file '. Rapp. history' and saves up to 250 entries.

How do I save my R console history?

Saving your workspace is how you save your data within R. Click on the Console window, go to the File menu and select “Save Workspace...”. In another R session, you open this workspace with the “Load Workspace...” command. To save everything that has scrolled past on the Console window, click on the Console window.

Where is R history stored?

R automatically saves an RHISTORY file (. RHistory, without a filename prefix) in the R working directory. Additionally, the user can manually save the command history using the application menu options.


2 Answers

First check your working directory (getwd()). savehistory() saves the history in the current working directory. And to be honest, you better specify the filename, as the default is .History. Say :

savehistory('C:/MyWorkingDir/MySession.RHistory')

which allows you to :

loadhistory('C:/MyWorkingDir/MySession.RHistory')

So the history is not lost, it's just in a place and under a name you weren't aware of. See also ?history.

To clarify : the history is no more than a text file containing all commands of that current session. So it's a nice log of what you've done, but I almost never use it. I construct my "analysis log" myself by using scripts, as hinted in another answer.

like image 143
Joris Meys Avatar answered Nov 14 '22 21:11

Joris Meys


@Stedy has provided a workable solution to your immediate question. I would encourage you to learn how to use .R files and a proper text editor, or use an integrated development environment (see this SO page for suggestions). You can then source() in your .R file so that you can consistently replicate your analysis.

For even better replicability, invest the time into learning Sweave. You'll be glad you did.

like image 39
Ari B. Friedman Avatar answered Nov 14 '22 22:11

Ari B. Friedman