I am not sure how exactly the history is implemented internally, and it
could be different depending on where and how you run R.  It looks like the
general rule for `savehistory` is to overwrite with the entire history
every time that you run it.

One way to get the behavior that you describe would be with the following
commands:

library(TeachingDemos)
con <- file('.Rhistory', open='a')
txtStart('ignoreme',commands=FALSE,results=FALSE, cmdfile=con)

# your commands here

txtStop()
close(con)
q('no')

Or you could use the task callback system more directly to append to the
history file at each step, since the above approach may be a bit of
overkill.

Note that the above will not save commands that result in an error, only
successful commands.  Whether that is a bug or a feature is for you to
decide



On Tue, Sep 17, 2013 at 2:11 AM, Mike Miller <mbmiller+l@gmail.com> wrote:

> In the bash shell we can use PROMPT_COMMAND="history -a" to tell bash to
> always append the last command to the history file.  It will do this with
> every command so that if bash crashes or an ssh connection is lost, the
> command history will still be available in the history file.
>
> With R, I see there is a savehistory() command (link below), but I have
> some questions:
>
> (1) does savehistory() append to the current history file or overwrite it?
>
> (2) if it appends, when savehistory() is evoked repeatedly, does it only
> append commands that haven't already been appended?  Or does it append the
> entire history to the file?
>
> (3) Is there a way to evoke history saving automatically so that the file
> is always updated?
>
>
> I have the impression that savehistory() only overwrites and cannot
> append.  If that's true, I might still get what I want, but I'd be doing a
> lot of unnecessary writing.  Luckily, my R history is usually quite short.
> So if I were to enter 100 commands, appending would write 100 lines, but
> overwriting would write 5050 lines.
>
>
> savehistory:
>
> http://stat.ethz.ch/R-manual/**R-devel/library/utils/html/**
> savehistory.html<http://stat.ethz.ch/R-manual/R-devel/library/utils/html/savehistory.html>
>
>
> Best,
> Mike
>
> --
> Michael B. Miller, Ph.D.
> Minnesota Center for Twin and Family Research
> Department of Psychology
> University of Minnesota
>
> ______________________________**________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
> PLEASE do read the posting guide http://www.R-project.org/**
> posting-guide.html <http://www.R-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538280@gmail.com

	[[alternative HTML version deleted]]

