savehistory {utils}R Documentation

Load or Save or Display the Commands History


Load or save or display the commands history.


loadhistory(file = ".Rhistory")
savehistory(file = ".Rhistory")
history( = 25, reverse = FALSE)


file The name of the file in which to save the history, or from which to load it. The path is relative to the current working directory. The maximum number of lines to show. Inf will give all of the currently available history.
reverse logical. If true, the lines are shown in reverse order. Note: this is not useful when there are continuation lines.


There are several history mechanisms available for the different R consoles, which work in similar but not identical ways. Other uses of R, in particular embedded uses, may have no history. This works in Rgui and interactive Rterm but not in batch use of Rterm nor in embedded/DCOM versions.

The history mechanism is controlled by two environment variables: R_HISTSIZE controls the number of lines that are saved (default 512), and R_HISTFILE sets the filename used for the loading/saving of history if requested at the beginning/end of a session (but not the default for these functions). There is no limit on the number of lines of history retained during a session, so setting R_HISTSIZE to a large value has no penalty unless a large file is actually generated.

These variables are read at the time of saving, so can be altered within a session by the use of Sys.putenv.


If you want to save the history (almost) every session, you can put a call to savehistory() in .Last.


## Not run: 
.Last <- function()
    if(interactive()) try(savehistory("~/.Rhistory"))
## End(Not run)

[Package utils version 2.1.0 Index]