Mark.Bravington@csiro.au
2002-Sep-19 04:54 UTC
savehistory directories and quitting R (PR#2038)
# # r-bugs@r-project.org # ###################################################### Because I work in different directories, but always want to save my .Rhistory in the same place, I have changed the system function savehistory to this: function (file = "D:/R50/.Rhistory") invisible(.Internal(savehistory(file))) When I use q() to quit R, and it asks me whether I want to "save current workspace", a response of YES means that the .Rhistory is saved in the current working directory, rather than D:/R50/.Rhistory. I take this to mean that the quit-on-prompt sequence makes a direct call to .Internal( savehistory...) rather than going via the actual savehistory() function. It would be nicer if prompt-on-quit would honour the user's definition of savehistory. (Responding NO to the "save current..." prompt means that .Rhistory isn't saved at all, which is reasonable.) I admit that this is a very minor bug, because I can set .Last to call savehistory directly. But I just thought you should know... 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 --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 1 minor = 5.0 year = 2002 month = 04 day = 29 language = R Windows 2000 Professional (build 2195) Service Pack 2.0 Search Path: .GlobalEnv, package:handy, package:debug, mvb.session.info, package:mvbutils, package:tcltk, Autoloads, package:base -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>Because I work in different directories, but always want to save my >.Rhistory in the same place, I have changed the system function savehistory >to this: > >function (file = "D:/R50/.Rhistory") >invisible(.Internal(savehistory(file))) > >When I use q() to quit R, and it asks me whether I want to "save current >workspace", a response of YES means that the .Rhistory is saved in the >current working directory, rather than D:/R50/.Rhistory. I take this to mean >that the quit-on-prompt sequence makes a direct call to .Internal( >savehistory...) rather than going via the actual savehistory() function. It >would be nicer if prompt-on-quit would honour the user's definition of >savehistory.What happens on shutdown is specific to the platform you're working on, but in both Windows and Unix versions, the filename is taken from the R_HISTFILE environment variable. I don't know if this works on the Mac. This would be more obvious if the R savehistory() function were changed to check the R_HISTFILE environment variable too. The problem with using the user's savehistory() function is that this violates the idea of namespaces that we're working towards: users should be able to create their own function named "savehistory" without worrying about changing important internal behaviour. Duncan Murdoch -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Fri, 20 Sep 2002 10:20:37 +1000, you wrote:>Thanks Duncan-- > >Intriguingly, this works if I set R_HISTFILE before starting R (via >.Renviron), but not if I do this within R: > >> Sys.putenv( 'R_HISTFILE'='D:/TEMP/.Rhistory') >> q() > > >Is that a bug? It could potentially cause problems if you change your mind >within a session about where history is to be saved. I have flirted with >doing this (because I switch projects within a session) but have decided not >to, for now.The internal variable that holds the value is set at startup. I don't think this is a bug, because I don't know of any documentation that suggests it would do anything else, but it probably would make sense to read the environment at the time the save is requested, rather than at startup.>BTW I can see why namespaces are almost essential if people are writing lots >of packages. But what if I actually WANT to fiddle about with system >behaviour? In the case of savehistory, I actually change the copy in "base" >as part of my .First, rather than creating a masking copy (can't remember >why I decided to do this, but still). Will I still be able to do this sort >of thing if I need to?I'm no expert on namespaces, but I think you can, similar to the way that you now save things into specific environments rather than the global one. Duncan Murdoch -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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-14 13:30 UTC
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. On Thu, 19 Sep 2002 Mark.Bravington@csiro.au wrote:> # > # r-bugs@r-project.org > # > ###################################################### > > Because I work in different directories, but always want to save my > .Rhistory in the same place, I have changed the system function savehistory > to this: > > function (file = "D:/R50/.Rhistory") > invisible(.Internal(savehistory(file))) > > When I use q() to quit R, and it asks me whether I want to "save current > workspace", a response of YES means that the .Rhistory is saved in the > current working directory, rather than D:/R50/.Rhistory. I take this to mean > that the quit-on-prompt sequence makes a direct call to .Internal( > savehistory...) rather than going via the actual savehistory() function. It > would be nicer if prompt-on-quit would honour the user's definition of > savehistory.Actually it talks directly to the GUI-specific history mechanism.> (Responding NO to the "save current..." prompt means that .Rhistory isn't > saved at all, which is reasonable.) > > I admit that this is a very minor bug, because I can set .Last to call > savehistory directly. But I just thought you should know... > > 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 > > > --please do not edit the information below-- > > Version: > platform = i386-pc-mingw32 > arch = i386 > os = mingw32 > system = i386, mingw32 > status > major = 1 > minor = 5.0 > year = 2002 > month = 04 > day = 29 > language = R > > Windows 2000 Professional (build 2195) Service Pack 2.0 > > Search Path: > .GlobalEnv, package:handy, package:debug, mvb.session.info, > package:mvbutils, package:tcltk, Autoloads, package:base > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._