[R] about lm

R. Michael Weylandt michael.weylandt at gmail.com
Sat Nov 17 18:17:40 CET 2012


On Sat, Nov 17, 2012 at 4:56 PM, FJ M <chicagobrownblue at hotmail.com> wrote:
>
> attach(attach(dat))
>
> should be
>
> attach(dat)
>
> Is attach() broken? I've been using attach() successfully for months. I was surprised that header=TRUE did not map the headers to the data. But since attach() worked, I've never asked for an enhancement to the various read functions.
>

No -- it's not broken, but it is dangerous (or more properly,
confusing). It has non-local effects by creating a whole bunch of
variables in the search path all at once. Combine that with the fact
that those new variables can't be written to and an apparent
sub/re-assignment really only creates global-environment copies (also
somewhat magically) and you have a recipe for confusion.

It's of course actually very important to the workings of R -- it's
key to package loading, inter alia -- but in my alternate universe,
it'd be hidden away, or at least start with a dot so it looks scarier.

Michael




More information about the R-help mailing list