Re: [R] *not* using attach() *but* in one case ....

From: <>
Date: Fri, 20 May 2011 09:11:01 +1000

>>>>>>> Martin Maechler writes: 

> Well, then you don't know *THE ONE* case where modern users of
> R should use attach() ... as I have been teaching for a while,
> but seem not have got enought students listening ;-) ...
> --- Use it instead of load() {for save()d R objects} ---
> The advantage of attach() over load() there is that loaded
> objects (and there maye be a bunch!), are put into a separate
> place in the search path and will not accidentally overwrite
> objects in the global "workspace".
> Of course, there are still quite a few situations {e.g. in
> typical BATCH use of R for simulations, or Sweaving, etc} where
> load() is good enough, and the extras of using attach() are not
> worth it.
> But the unconditional "do not use attach()"
> is not quite ok,
> at least not when you talk to non-beginners.
> Martin Maechler, ETH Zurich

Curiously this is why I wrote the SOAR package. Instead of save() you use Store() (Frank Harrell had already taken 'Save') and instead of attach() use Attach(). The objects are saved as separate rda files in a special subdirectory and when Attach() is used on it they are placed on the search path, normally at position 2, as promises. The global environment is kept relatively free of extraneous objects (if you want to work like that) and the operation is fast and very low on memory use, (unless you want to use every object you see all at once, of course).

The "track" package from Tony Plate achieves somewhat similar results but with a different method. Essentially it implements something very like the old S-PLUS style of keeping everything out of memory as files in a .Data subdirectory, (although Tony uses the name 'rdatadir'), unless actually in use.

Bill Venables. mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 19 May 2011 - 23:13:13 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 May 2011 - 23:40:08 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive