[R] detach()

Thomas Lumley tlumley at u.washington.edu
Mon Mar 22 22:34:06 CET 2004

On Mon, 22 Mar 2004, Rolf Turner wrote:
> If, more realistically, you did
> melvin <- grep("women",search())
> detach(melvin)
> I would expect the data set ``women'' to be detached.  My
> expectations would of course be dashed.  The current structure of
> detach() seems to me to be a counterintuitive contortion designed to
> protect the user from doing something stupid.  Maybe that's a good
> thing.

I think the motivation may have been that attach() and detach() (like
rm(), data(), and help(), which have the same problem) are rarely used in
programming, and that programmers can use detach(pos=).

It was certainly deliberate, but may well have been a mistake.  One could
even argue that the symmetry between attach(women) and detach(women) is
misleading, and encourages the misconception that attach() puts the object
in the search path, rather than a copy of the object.


More information about the R-help mailing list