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

Gavin Simpson gavin.simpson at ucl.ac.uk
Wed Sep 22 10:36:01 CEST 2010


On Tue, 2010-09-21 at 21:34 -0700, Joshua Wiley wrote:
> Hi all,
> 
> I am wondering if anyone teaches the attach function to new students
> and if so, why?

I don't use attach() at all; too easy to make mistakes that are
difficult to track down. I tend not to use $ either as that encourages
people to use it to go fiddling in the bowels of other lists (objects);
model$residuals might be OK for lm() models (though not if you've used
na.exclude for example) but students might be surprised with what they
get with more complex modelling functions with different residuals.

If I was really teaching R, I would mention attach() and then show why
it is bad so I've dealt with the issue on my terms.

G

> I have never taught a class using R, but in small tutorials and
> providing direct help, I have run across this issue several times.  I
> have always avoided it, but a couple of times, students had learned to
> use it in a class (though without much detail) and were rather grumpy
> with me for using full variable names or with().  New converts,
> particularly from GUIs like SPSS, already tend to be leery of R, and I
> hate to make working at the command line more onerous since any typing
> is more than they are used to, but at the same time a discussion of
> environments, which I think is necessary to avoid trouble with attach,
> does not seem like beginner material either.
> 
> I have wondered about this many times, but was just reminded again by
> an R-help post.
> 
> Thanks,
> 
> Josh
> 

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%




More information about the R-sig-teaching mailing list