[R] *not* using attach() *but* in one case ....
Bill.Venables at csiro.au
Bill.Venables at csiro.au
Fri May 20 01:11:01 CEST 2011
>>>>>>> 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.
More information about the R-help
mailing list