(On Unix/Linux) Is it possible to set the --no-save command line option as an option in the .Rprofile file. I have looked in the sources and do not see any obvious (user initiated) ways of changing the command line defaults, but I am hoping I have missed something. I *know* I can write my own shell script wrapper that calls R with whatever arguments I want (and I do that). However there are times when I would like to have per-directory control of R, just as the Rprofile file does it. (And yes, it would be trivial to write an R wrapper that looked for a file in the local directory that contained command line arguments, I just don't want to invent that wheel unless there is nothing simpler). Regards, --Mike Mike Meyer, Salter Point Associates, Seattle WA -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 17 Jan 2001, Michael M. Meyer wrote:> (On Unix/Linux) > Is it possible to set the --no-save command line option as an option > in the .Rprofile file. I have looked in the sources and do not see > any obvious (user initiated) ways of changing the command line defaults, > but I am hoping I have missed something. > > I *know* I can write my own shell script wrapper that calls R with > whatever arguments I want (and I do that). However there are times > when I would like to have per-directory control of R, just as the > Rprofile file does it. > > (And yes, it would be trivial to write an R wrapper that looked for a > file in the local directory that contained command line arguments, > I just don't want to invent that wheel unless there is nothing simpler).Interesting: no, you can't set this as it gets used at a very early stage: in batch use it is checked before launching R. However, it is only actually used in two cases (as far as I remember): (i) As the default arg for q() (ii) With an implicit q() at the end of file in batch use. For the first, you can re-define q() in the .Rprofile, as q <- function (save = "no", status = 0, runLast = TRUE) .Internal(quit(save, status, runLast)) For the second you can do nothing, but you will have had to specify the option in the command line, anyway. (Certain error actions such as user signals also quit, but they all specify save/nosave.) Is this enough? We could provide an options argument to set the default in q(), or just make it a settable R variable, say .quit.default, if there was a need not met by the above. I assume you are not using the GNOME GUI. That has the annoying (and as far as I know undocumented) side-effect of saving the --save/--no-save/ask setting in its configuration file and using it next time around. Only, there is no way to specify "ask" on the command line, so the only way to get back to it is to edit the configuration file. -- 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Thanks to Brian Ripley and Robert Gentleman who both suggested adding rgentlem at jimmy.harvard.edu said:> q<-function (save = "no", status = 0, runLast = TRUE) > .Internal(quit(save, status, runLast))to the .Rprofile. While this works (and I might use it), it is not as clean as I would like. For instance, with this profile, if I subsequently run R --save the "--save" will be ignored. It would seem a good solution might be to allow something in the environement (or .Renvironment file) like R_OPTIONS = "--nosave --noreadline ..." One could then (logically) parse those options before the command line is read, and have the command line override anything set in the R_OPTIONS string. The one wrinkle is the --no-init-file option. So I guess the logic has to go something like. 1) Read command line args (and save them somewhere). 2) if(exists(.Rprofile) and we should read it) parse that file. 3) re-parse command line options to override the init file. If one were to go this route, then one probably needs a --save-ask command line option, to restore the default behaviour. Maybe this is getting too complicated, and I''ll just write my little wrapper function, #!/bin/sh if ([ -f .Roptions ]) then exec R `cat .Roptions` $* elif ([ -f $HOME/.Roptions ]) then exec R `cat $HOME/.Roptions` $* else exec R $* fi Mike Meyer, Salter Point Associates, Seattle WA -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Date: Thu, 18 Jan 2001 07:03:50 -0800 > From: "Michael M. Meyer" <mikem at salter-point.com> > > Thanks to Brian Ripley and Robert Gentleman > who both suggested adding > > rgentlem at jimmy.harvard.edu said: > > q<-function (save = "no", status = 0, runLast = TRUE) > > .Internal(quit(save, status, runLast)) > > to the .Rprofile. > > While this works (and I might use it), it is not as clean as I would > like. For instance, with this profile, if I subsequently run > R --save > the "--save" will be ignored. > > It would seem a good solution might be to allow something in the > environement (or .Renvironment file) like > > R_OPTIONS = "--nosave --noreadline ..." > > One could then (logically) parse those options before the command line isread,> and have the command line override anything set in the R_OPTIONS > string. The one wrinkle is the --no-init-file option. So I guess the > logic has to go something like. > 1) Read command line args (and save them somewhere). > 2) if(exists(.Rprofile) and we should read it) parse that file. > 3) re-parse command line options to override the init file. > > If one were to go this route, then one probably needs a > --save-ask > command line option, to restore the default behaviour. > > Maybe this is getting too complicated, and I''ll just write my little > wrapper function,Yes, it is, and one needs a precedence anyway. Remember that R comes with half a dozen front-ends and three major groups of OSes. The logic is 1) The front-ends set some internal variables, usually via flags, and set some environment variables via parsing .Renviron. 2) Then the R parser is started, and reads .Rprofile. On most platform that reads some environment variables to set defaults. 3) Eventually a prompt appears with lots of things in the gaps. It is not at all easy to go backwards in the sequence. After all, one platform (Mac) does not even have environment variables. Brian -- 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 18 Jan 2001, Michael M. Meyer wrote:> Thanks to Brian Ripley and Robert Gentleman > who both suggested adding > > rgentlem at jimmy.harvard.edu said: > > q<-function (save = "no", status = 0, runLast = TRUE) > > .Internal(quit(save, status, runLast)) > > to the .Rprofile. > > While this works (and I might use it), it is not as clean as I would > like. For instance, with this profile, if I subsequently run > R --save > the "--save" will be ignored. >You can get around this using commandArgs() to find out if --save was specified (at least on Unix, I haven''t checked on Windows) Define qsave() and qnosave() as quit functions with the "no" and"yes" defaults and then if (match("--save",commandArgs(),FALSE)) q<-qsave else q<-qnosave -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help 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-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._