[R-sig-teaching] pros/cons of teaching attach()

Douglas Bates bates at stat.wisc.edu
Wed Sep 22 14:10:14 CEST 2010


On Wed, Sep 22, 2010 at 4:04 AM, Joshua Wiley <jwiley.psych at gmail.com> wrote:
> Thanks to everyone for your thoughtful replies.  I think I am inclined
> not to use attach, but to bring it up and briefly mention some of the
> mistakes that are easy to make.  If students already know/use attach,
> it will at least be clear why I do not use it, and for students
> unfamiliar with it, they should not be tempted to start.
>
> Thanks again for all the responses!

I avoid teaching attach() and discourage its use if the students have
already seen it.  I do teach both with and within (with provides
read-only access, within provides read-write access to the variable
names in a data frame or a list).  As mentioned in an earlier reply in
this thread, the use of extractor functions, like residuals() or
fitted() or coef(), should be preferred to reaching inside a data
object and grabbing a component that may or may not continue to be
defined in future versions,

The supplementary material on R that I use in a first-year grad course
on applied statistics is available, for this semester, at
www.stat.wisc.edu/~st849-1/Rnotes  My approach to data organization is
shown in the "Introduction to R".




More information about the R-sig-teaching mailing list