Skip to Content

In R do you use attach() or call variables by name or slicing?

Many intro R books and guides start off with the practice of attaching a data.frame so that you can call the variables by name. I have always found it favorable to call variables with $ notation or square bracket slicing [,2]. That way I can use multiple data.frames without confusing them and/or use iteration to successively call columns of interest. I noticed Google recently posted coding guidelines for R (http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html) which included the line

1) attach: avoid using it

How do people feel about this practice?