savehistory()
and solves the problem of
command history not being saved on accidental or abnormal termination
of an R session.
track.history.start(file = NULL, width = NULL, style = NULL, times = NULL, load = TRUE, verbose = FALSE, message="Session start")
track.history.stop()
track.history.status()
track.history.load(times = FALSE)
track.history.writer(expr, value, ok, visible)
.Rincr_history
.
120
.
full
: (default) Use the internal R history mechanism. This is slower, but it records everything typed
at the command prompt, in the original formatting.
fast
: Use deparsed version of the
most recently executed command. This is fast, but it doesn't record
comments and some commands with errors, and it changes formatting.
track.history.start()
is TRUE
. The default
when loading history is FALSE
, so that time stamps do not
appear in the interactive history.
track.history.status()
returns a character string: "on"
or "off"
.
The other functions currently provide no useful return values.
incr.hist.style
,
incr.hist.width
, incr.hist.file
and
incr.hist.times
.
If those option values don't exist, values are taken from environment
variables R_INCR_HIST_STYLE
, R_INCR_HIST_WIDTH
,
R_INCR_HIST_FILE
, R_INCR_HIST_TIMES
.
track.history.start()
installs track.history.writer()
as a task callback handler.
track.history.load()
loads history from the file that
incremental history is being written to.
track.history.stop()
removes the task callback handler.
track.history.writer()
is the task callback handler -- it is
not intended to be called by the user.
If arguments are supplied to track.history.start()
, their
values are remembered in options()
and used for the remainder
of the session or until changed.
The history stored using style="full"
is more complete and
accurate, in that it includes comments, unparseable commands, and
original formatting. It is somewhat slower because it is based
on the internal history mechanism, which doesn't provide an easy way of
identifying which are the new commands. Consequently, when using
style="full"
track.history.writer()
must inspect the
entire internal history at the end of each command to work out which
lines in it have been added since the last time history was written.
However, the time difference seems negligible for interactive use on
ordinary workstations circa 2010.
To set up incremental history tracking automatically, put the
following in your .Rprofile
:
if (interactive()) { track.history.load() track.history.start() }
addTaskCallback
To read in command history that is stored in a particular file, use
loadhistory(file)
.
savehistory
## Not run:
# ## Can't use history except in Rgui and Rterm
# track.history.start()
# ## End(Not run)
Run the code above in your browser using DataLab