[R] attach (S-style)?

Martin Maechler maechler at stat.math.ethz.ch
Thu May 18 17:00:43 CEST 2000


>>>>> "ChHo" == Christian Hoffmann <christian.hoffmann at wsl.ch> writes:

    ChHo> Hi everyone, Being new to the crowd of R users I am wondering
    ChHo> what the equivalent of

    ChHo>      attach("/home/bla/hoffmann/R/.RData",2) 

    ChHo> (S style) is in R.

    ChHo> What I want is a split of .RData repositories. One in a central
    ChHo> place where I keep functions and interesting stuff important for
    ChHo> all work I am doing, an several others which contain stuff of an
    ChHo> dividual project only. When I start in a project directory I want
    ChHo> to make available the central stuff. If I do it like in S+ I am
    ChHo> getting and rightly so:

    ChHo> Error in attach("/home/woodstock/hoffmann/R/.RData", 2) : 
    ChHo> attach only works for lists and data frames

    ChHo> What is the trick to use in R?

You use packages [via library()] ==>  help(library) and help(INSTALL)
				 and the "Writing R Extensions" Manual
and then you can add a
    library(my.important.stuff)
to a local or a site-wide  Rprofile file such that it is 
automatically there.

If you really want to get at the content of .RData (binary) files,
you use load(.), but this adds the objects to your ".GlobalEnv"
i.e.,  search()[1].
If you want be even smarter, you can look how the library() command
"does it" and probably do the same, using  load() instead of [sys.]source().

But anyway, as said initially : Using packages is what you should do ...

On creating your own packages, the R-FAQ says
>>    See section "Creating R packages" in `Writing R Extensions', for details.
>> This manual is included in the R distribution, *note What documentation
>> exists for R?::, and gives information on package structure, the configure
>> and cleanup mechanisms, and on automated package checking and building.

---

I hope this helps to get you started.

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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