Skip to content
Back to formatted view

Raw Message

Message-ID: <CAAmySGM4NaQgJSsRHf4kPLfBUXMPTOo9Obo06pNkuNMx2BTHTg@mail.gmail.com>
Date: 2012-11-17T17:17:40Z
From: R. Michael Weylandt
Subject: about lm
In-Reply-To: <BLU161-W22037AD0237585FA75BCCBDF500@phx.gbl>

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