savehistory {utils} | R Documentation

## Load or Save or Display the Commands History

### Description

Load or save or display the commands history.

### Usage

    loadhistory(file = ".Rhistory")
    savehistory(file = ".Rhistory")

    history(max.show = 25, reverse = FALSE, pattern, ...)

    timestamp(stamp = date(),
              prefix = "##------ ", suffix = " ------##",
              quiet = FALSE)

### Arguments

`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.
`max.show` | 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.
`pattern` | A character string to be matched against the lines of the history. When supplied, only unique matching lines are shown.
`...` | Arguments to be passed to `grep` when doing the matching.
`stamp` | A value or vector of values to be written into the history.
`prefix` | A prefix to apply to each line.
`suffix` | A suffix to apply to each line.
`quiet` | If `TRUE`, suppress printing timestamp to the console.

### Details

There are several history mechanisms available for the different R consoles, which work in similar but not identical ways. There are separate versions of this help file for Unix and Windows.

The functions described here work in `Rgui` and interactive `Rterm` but not in batch use of `Rterm` nor in embedded/DCOM versions.

The history mechanism is is controlled by two environment variables: R_HISTSIZE controls the number of lines that are saved (default 512), and R_HISTFILE (default ‘.Rhistory’) sets the filename used for the loading/saving of history if requested at the beginning/end of a session (but not the default for `loadhistory`/`savehistory`). 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 environment variables are read at the time of saving, so can be altered within a session by the use of `Sys.setenv`.

The `timestamp` function writes a timestamp (or other message) into the history and echos it to the console. On platforms that do not support a history mechanism only the console message is printed.

### Note

If you want to save the history at the end of (almost) every interactive session (even those in which you do not save the workspace), you can put a call to `savehistory()` in `.Last`. See the examples.

### Examples

    ## Not run:
    ## Save the history in the home directory: note that it is not
    ## (by default) read from there but from the current directory
    .Last <- function()
        if(interactive()) try(savehistory("~/.Rhistory"))

    ## End(Not run)

[Package utils version 3.3.0 Index]