How can I access a function created in one data directory in another? I have been sourcing the text file that contains the function each time I go to another data dir. This is cumbersome, and I suspect there is a way to make functions global. Thanks in advance, S. David White Dept of Speech and Hearing Science Ohio State University Columbus, Ohio -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Kaspar Pflugshaupt
2001-Mar-23 08:20 UTC
[R] newbie questions: accessing functions globally
On Thursday 22 March 2001 21:58, David White wrote:> How can I access a function created in one data directory in another? I > have been sourcing the text file that contains the function each time I go > to another data dir. This is cumbersome, and I suspect there is a way to > make functions global. > > Thanks in advance,There are several ways to achieve this. The ultimate solution would be to pack your functions into a package and have it loaded at startup. See the "Writing R Extensions" manual for more information on this. For other ways see help(.First). I'm using the following in my .First function: attach("/home/pflugs/R/my.functions.R") "my.functions.R" is a normal text file, created by dump(). It can also contain data sets that I use frequently. This works from wherever I am and I can keep my personal functions in one place (making editing them easy). What's more, the functions don't "pollute" my workspace (which tends to get overfull anyway), because they get attached at their own position in the search() list. I have to define .First each time I start a new working directory, but that's a minor inconvenience. My 2 Rp Kaspar Pflugshaupt -- Kaspar Pflugshaupt Geobotanical Institute ETH Zurich, Switzerland http://www.geobot.umnw.ethz.ch mailto:pflugshaupt at geobot.umnw.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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Kaspar Pflugshaupt
2001-Mar-26 06:24 UTC
[R] newbie questions: accessing functions globally
On Monday 26 March 2001 01:36, Patrick Connolly wrote:> > The most closely analagous way would be to create a .First function in > a location and save that as the only thing in .RData which I could use > the same way as I've used ./.Data/.First in Splus. I've not looked > into `R_ENVIRON' or `~/.Renviron' as described in the help on .First. > Perhaps you've investigated it and can tell me if my idea is superior, > or indeed if it is completely silly.I haven't played with R_ENVIRON yet. I'm sure it could be used to the same effect, though. Your idea doesn't sound silly. Let's see... pflugs at Aconitum:~ > R --vanilla # start with an empty workspace R : Copyright 2001, The R Development Core Team Version 1.2.2 (2001-02-26) [...] Type `q()' to quit R.> .First <- function() attach("/home/pflugs/R/my.functions.R") > save.image()gives a .RData file with just .First() in it. If we copy this into a new directory, R should load it automagically when started in that directory and execute the .First function:> q()pflugs at Aconitum:~ > mkdir RTest pflugs at Aconitum:~ > cp .RData RTest pflugs at Aconitum:~ > cd RTest/ pflugs at Aconitum:~/RTest > R R : Copyright 2001, The R Development Core Team Version 1.2.2 (2001-02-26) [...] [Previously saved workspace restored]> search()[1] ".GlobalEnv" "file:/home/pflugs/R/my.functions.R" [3] "Autoloads" "package:base" works as expected. I think I'll use this in the future. Thanks for the idea! Cheers Kaspar -- Kaspar Pflugshaupt Geobotanical Institute ETH Zurich, Switzerland http://www.geobot.umnw.ethz.ch mailto:pflugshaupt at geobot.umnw.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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._