[R] newbie questions: accessing functions globally

Kaspar Pflugshaupt pflugshaupt at cirsium.ethz.ch
Fri Mar 23 09:20:00 CET 2001


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list