On Tue, Oct 29, 2002 at 10:11:09AM +0100, Jan Malte Wiener wrote: ...> thought a UNIX environment variable could be the solution, but R doesn't > seem to know about the environment variables. > e.g. >> source("$PROJECT/xxx.R") results in > >> Error in file(file, "r") : unable to open connection > > is there something like environment variables for R?Yep. Sys.getenv() Cheers Jason -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
hi, i am working on a little R-project with a couple od other guys.we use CVS, but everyone keeps the R-source files in different locations in his home-directory. of course this causes trouble when sourcing R-files. i thought a UNIX environment variable could be the solution, but R doesn't seem to know about the environment variables. e.g. >> source("$PROJECT/xxx.R") results in >> Error in file(file, "r") : unable to open connection is there something like environment variables for R? greetinx jan -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> hi, > i am working on a little R-project with a couple od other guys.we use > CVS, but everyone keeps the R-source files in different locations in his > home-directory. of course this causes trouble when sourcing R-files. i > thought a UNIX environment variable could be the solution, but R doesn't > seem to know about the environment variables. > e.g. >> source("$PROJECT/xxx.R") results in > >> Error in file(file, "r") : unable to open connection > > is there something like environment variables for R??Sys.getenv very useful for passing things into an R session.> > greetinx jan > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Roger Bivand NHH, Breiviksveien 40, N-5045 Bergen, Norway (travelling but still accessible) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
One way to do this would be to change to the $PROJECT directory and then use source. For example:> setwd(Sys.getenv("PROJECT")) > source("xxx.R")If you wish to remain the current directory after executing the souce then save the current location with:> currdir <- getwd()Then after sourcing change back to the current directory:> setwd (currdir)So the sequence of commands could be:> currdir <- getwd() > setwd(Sys.getenv("PROJECT")) > source("xxx.R") > setwd (currdir)HTH, Partha. Jan Malte Wiener <jan.wiener at tuebingen.mpg.de> Sent by: owner-r-help at stat.math.ethz.ch 10/29/2002 06:37 AM To: Jason Turner <jasont at indigoindustrial.co.nz>, R <r-help at stat.math.ethz.ch> cc: Subject: Re: [R] unix environment variables under R Jason Turner wrote:> On Tue, Oct 29, 2002 at 10:11:09AM +0100, Jan Malte Wiener wrote: > ... > >>thought a UNIX environment variable could be the solution, but R doesn't >>seem to know about the environment variables. >>e.g. >> source("$PROJECT/xxx.R") results in >> >> Error in file(file, "r") : unable to open connection >> >>is there something like environment variables for R? > > > Yep. Sys.getenv() > > Cheers > > Jasonthanks for your answer, but how do i source a file using that environment variable; if the environment variable holds a path to a directory and i want to source a file within that directory?? e.g.: Sys.putenv("ABC"="~/R-Stuff/") in ~/R-Stuff there a bunch of R-files now i want to source one of these R-files using the ABC environment variable. sorry, but i do not know how to do this ? greetinx jan -- Jan Malte Wiener Max-Planck-Institute for Biological Cybernetics Spemannstr. 38, 72076 Tuebingen, Germany Tel.: +49 7071 601 631 Email: jan.wiener at tuebingen.mpg.de -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi! Sys.getenv() does the job. detlef On 29-Oct-2002 Jan Malte Wiener wrote:> hi, > i am working on a little R-project with a couple od other guys.we use > CVS, but everyone keeps the R-source files in different locations in his > home-directory. of course this causes trouble when sourcing R-files. i > thought a UNIX environment variable could be the solution, but R doesn't > seem to know about the environment variables. > e.g. >> source("$PROJECT/xxx.R") results in > >> Error in file(file, "r") : unable to open connection > > is there something like environment variables for R? > > greetinx jan > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. > - > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. > _"There is no way to peace, peace is the way." -- Ghandi Detlef Steuer --- http://fawn.unibw-hamburg.de/steuer.html ***** Encrypted mail preferred ***** -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Jan Malte Wiener wrote:>hi, >i am working on a little R-project with a couple od other guys.we use >CVS, but everyone keeps the R-source files in different locations inhis>home-directory. of course this causes trouble when sourcing R-files. i >thought a UNIX environment variable could be the solution, but Rdoesn't>seem to know about the environment variables. >e.g. >> source("$PROJECT/xxx.R") results in > >> Error in file(file, "r") : unable to open connection > >is there something like environment variables for R?What about:> paste(system("echo $HOME",T),"sourcefile.r",sep="/")or> source(paste(system("echo $HOME",T),"sourcefile.r",sep="/"))Peter Wolf -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._