[R] newbie questions: accessing functions globally

Kaspar Pflugshaupt pflugshaupt at cirsium.ethz.ch
Mon Mar 26 08:24:26 CEST 2001


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



More information about the R-help mailing list