Dear R users,
I have a .RData which contains .Last object as follows:
.Last <- function ()
{
savehistory(file = ".Rhistory")
}
In this directory, if I issue the following command
Rterm --save < mycmds.q
to execute commands in mycmds.q and to save results in .RData,
I got the following error message towards the end of the execution:
Error in savehistory(file) : savehistory can only be used
in Rgui and Rterm
Execution halted
I lost the results of the commands too. The documentation of
"savehistory" says that it only works with Rgui and Rterm. Why
doesn't it work in this case? Is it because it is in a batch mode
rather than in an interactive mode? I did this in Windows98 with
the following R
> version
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 1
minor 6.2
year 2003
month 01
day 10
language R
I tested it in Linux with the same version R and the same problem
happened.
Is it possible to prevent savehistory from printing the error message
so that the session can be finished properly? I hope that I did not
miss anything obvious. Otherwise, please forgive me. Thanks.
Paul.
savehistory not working properly in R?
5 messages · Paul Y. Peng, Brian Ripley, Patrick Connolly
On Wed, 14 May 2003, Paul Y. Peng wrote:
I have a .RData which contains .Last object as follows:
.Last <- function ()
{
savehistory(file = ".Rhistory")
}
In this directory, if I issue the following command
Rterm --save < mycmds.q
to execute commands in mycmds.q and to save results in .RData,
I got the following error message towards the end of the execution:
Error in savehistory(file) : savehistory can only be used
in Rgui and Rterm
Execution halted
I lost the results of the commands too. The documentation of
"savehistory" says that it only works with Rgui and Rterm. Why
doesn't it work in this case? Is it because it is in a batch mode
rather than in an interactive mode?
Yes. The history is associated with the command-line editing: what you are doing is considered to be BATCH use.
I did this in Windows98 with the following R
> version
platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 1 minor 6.2 year 2003 month 01 day 10 language R I tested it in Linux with the same version R and the same problem happened. Is it possible to prevent savehistory from printing the error message so that the session can be finished properly? I hope that I did not miss anything obvious. Otherwise, please forgive me. Thanks.
The real problem is in your .Last. You could do
.Last <- function ()
{
if(interactive()) savehistory(file = ".Rhistory")
}
or use try(): if you are worried about not saving .RData you really
should protect the commands in .Last (see its help page for warnings).
I'll see if the documentation can be clarified.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Prof Brian Ripley wrote:
On Wed, 14 May 2003, Paul Y. Peng wrote:
I have a .RData which contains .Last object as follows:
.Last <- function ()
{
savehistory(file = ".Rhistory")
}
In this directory, if I issue the following command
Rterm --save < mycmds.q
to execute commands in mycmds.q and to save results in .RData,
I got the following error message towards the end of the execution:
Error in savehistory(file) : savehistory can only be used
in Rgui and Rterm
Execution halted
I lost the results of the commands too. The documentation of
"savehistory" says that it only works with Rgui and Rterm. Why
doesn't it work in this case? Is it because it is in a batch mode
rather than in an interactive mode?
Yes. The history is associated with the command-line editing: what you are doing is considered to be BATCH use.
Is it possible to prevent savehistory from printing the error message so that the session can be finished properly? I hope that I did not miss anything obvious. Otherwise, please forgive me. Thanks.
The real problem is in your .Last. You could do
.Last <- function ()
{
if(interactive()) savehistory(file = ".Rhistory")
}
Many thanks. As always, your suggestion works. I should have thought about interactive().
or use try(): if you are worried about not saving .RData you really should protect the commands in .Last (see its help page for warnings).
I will give try() a real try. It seems to be quite useful.
I'll see if the documentation can be clarified.
Why does R save its command history only when one saves the data image of the session? Is this a feature? Even though .Last can do this, would it be more convenient if R can do this automatically? Logically, I feel the command history should be treated separately. Paul.
On Thu, 15 May 2003, Paul Y. Peng wrote:
Why does R save its command history only when one saves the data image of the session? Is this a feature? Even though .Last can do this, would it be more convenient if R can do this automatically? Logically, I feel the command history should be treated separately.
I don't know: it predates my involvement with R. The Windows ports used always to save it, but we changed to conform to the Unix version, since being different confused too many people.
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Thu, 15-May-2003 at 02:51PM -0230, Paul Y. Peng wrote:
|> Why does R save its command history only when one saves the data |> image of the session? Is this a feature? Even though .Last can do |> this, would it be more convenient if R can do this automatically? |> Logically, I feel the command history should be treated separately. I like it how it is. I always have at least two R sessions active. One I'm working on and the other I use for tinkering with ideas that come up from reading this list. I don't usually want to keep a history of those tinkerings, so I quit the tinkering R session without saving a data image. best
Patrick Connolly HortResearch Mt Albert Auckland New Zealand Ph: +64-9 815 4200 x 7188 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ I have the world`s largest collection of seashells. I keep it on all the beaches of the world ... Perhaps you`ve seen it. ---Steven Wright ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~