Skip to content

newbie questions: accessing functions globally

2 messages · David White, Kaspar Pflugshaupt

#
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Thursday 22 March 2001 21:58, David White wrote:

            
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