Mark.Bravington@csiro.au
2002-Oct-21  23:41 UTC
savehistory directories and quitting R (PR#2038)
Thanks-- as Duncan Murdoch also noted, R_HISTFILE can be used to solve my
problem, as below. BTW it's not easy to find out about R_HISTFILE in the
help system or manuals, though, unless you already know it exists-- it only
seems to be described under startup options, not things to do with history.
However, Duncan's reply did hint at an inconsistency, in that savehistory()
defaults to using a file called .Rhistory in getwd(), rather than using
R_HISTFILE. I've modified my savehistory to default to R_HISTFILE if it
exists, like so:
savehistory_ function( file) {
  if( missing( file) && is.null( file <- Sys.getenv(
'R_HISTFILE')))
    file <- '.Rhistory'
  get( 'savehistory', pos='package:base')( file)
}
#This is not a bug. If you override a system function, you 
#can't expect it
#to be used by R internals.  Indeed, as from 1.6.0 you can't 
#even expect it
#to be used by R's base functions, due to namespaces.
With an eye to namespace-like issues, I originally put some code in .First
to overwrite the version of savehistory within package:base, rather than
simply masking it with a copy in .GlobalEnv. But, since savehistory wasn't
actually called at quit time, even that didn't fool the system...
cheers
Mark
*******************************
Mark Bravington
CSIRO (CMIS)
PO Box 1538
Castray Esplanade
Hobart
TAS 7001
phone (61) 3 6232 5118
fax (61) 3 6232 5012
Mark.Bravington@csiro.au 
#-----Original Message-----
#From: ripley@stats.ox.ac.uk [mailto:ripley@stats.ox.ac.uk]
#Sent: Tuesday, 15 October 2002 12:31 AM
#To: Mark.Bravington@csiro.au
#Cc: r-devel@stat.math.ethz.ch; R-bugs@biostat.ku.dk
#Subject: Re: savehistory directories and quitting R (PR#2038)
#
#
#This is not a bug. If you override a system function, you 
#can't expect it
#to be used by R internals.  Indeed, as from 1.6.0 you can't 
#even expect it
#to be used by R's base functions, due to namespaces.
#
#There are very good reasons for the internal quit code not to 
#call user's
#R code, the main one being that R errors will not be handled then.
#.Last is made available as a hook to enable you to do what you want:
#as the help page says.
#
#Doesn't setting R_HISTFILE do this for you automatically? Just set
#R_HISTFILE="D:/R50/.Rhistory" and the history should be loaded 
#and saved
#to the specified place.  Works under Unix, at least.
#
#
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To:
r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ripley@stats.ox.ac.uk
2002-Oct-22  06:53 UTC
savehistory directories and quitting R (PR#2038)
On Tue, 22 Oct 2002 Mark.Bravington@csiro.au wrote:> Thanks-- as Duncan Murdoch also noted, R_HISTFILE can be used to solve my > problem, as below. BTW it's not easy to find out about R_HISTFILE in the > help system or manuals, though, unless you already know it exists-- it only > seems to be described under startup options, not things to do with history. > > However, Duncan's reply did hint at an inconsistency, in that savehistory() > defaults to using a file called .Rhistory in getwd(), rather than using > R_HISTFILE. I've modified my savehistory to default to R_HISTFILE if it > exists, like so:Yes, intentional. Note that it is not R_HISTFILE used, but its value at the beginning of the session ....> > savehistory_ function( file) { > if( missing( file) && is.null( file <- Sys.getenv( 'R_HISTFILE'))) > file <- '.Rhistory' > get( 'savehistory', pos='package:base')( file) > } > > #This is not a bug. If you override a system function, you > #can't expect it > #to be used by R internals. Indeed, as from 1.6.0 you can't > #even expect it > #to be used by R's base functions, due to namespaces. > > With an eye to namespace-like issues, I originally put some code in .First > to overwrite the version of savehistory within package:base, rather than > simply masking it with a copy in .GlobalEnv. But, since savehistory wasn't > actually called at quit time, even that didn't fool the system... > > cheers > Mark > > ******************************* > > Mark Bravington > CSIRO (CMIS) > PO Box 1538 > Castray Esplanade > Hobart > TAS 7001 > > phone (61) 3 6232 5118 > fax (61) 3 6232 5012 > Mark.Bravington@csiro.au > > #-----Original Message----- > #From: ripley@stats.ox.ac.uk [mailto:ripley@stats.ox.ac.uk] > #Sent: Tuesday, 15 October 2002 12:31 AM > #To: Mark.Bravington@csiro.au > #Cc: r-devel@stat.math.ethz.ch; R-bugs@biostat.ku.dk > #Subject: Re: savehistory directories and quitting R (PR#2038) > # > # > #This is not a bug. If you override a system function, you > #can't expect it > #to be used by R internals. Indeed, as from 1.6.0 you can't > #even expect it > #to be used by R's base functions, due to namespaces. > # > #There are very good reasons for the internal quit code not to > #call user's > #R code, the main one being that R errors will not be handled then. > #.Last is made available as a hook to enable you to do what you want: > #as the help page says. > # > #Doesn't setting R_HISTFILE do this for you automatically? Just set > #R_HISTFILE="D:/R50/.Rhistory" and the history should be loaded > #and saved > #to the specified place. Works under Unix, at least. > # > # >-- Brian D. Ripley, ripley@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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._