Deal of the Day

Home » Main » Manning Forums » 2009 » R in Action

Thread: Use of Attach

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 2 - Pages: 1 - Last Post: Jan 24, 2010 5:39 PM by: robert.kabacoff Threads: [ Previous | Next ]
kpierce8

Posts: 2
Registered: 5/21/09
Use of Attach
Posted: Aug 26, 2009 3:20 PM
  Click to reply to this thread Reply

I see you use the attach() function often, as do most authors. I think you should include some caveats about attach. It makes for more succunct code in a book but is potentially fraught with pitfalls. The most obvious is multiple tables with similarly named variables. It is the equvalent of making all your variables global scope. I find methods such as explicit naming, column slicing and use of with() to make for better, more repeatable data analysis scripts.

robert.kabacoff

Posts: 74
Registered: 8/3/09
Re: Use of Attach
Posted: Nov 5, 2009 3:29 PM   in response to: kpierce8 in response to: kpierce8
  Click to reply to this thread Reply

I would agree when you are writing code to use in batch. In an interactive session, I have separate environments for each project that I am working on and it is very unlikely that I will use more than one dataframe in a session.In this case, I find the use of the attach function very helpful.

It is a good idea to talk about attach/detach and with. I will try to work it in.

Thanks for the idea.

Sincerely,

Rob

robert.kabacoff

Posts: 74
Registered: 8/3/09
Re: Use of Attach
Posted: Jan 24, 2010 5:39 PM   in response to: robert.kabacoff in response to: robert.kabacoff
  Click to reply to this thread Reply

I am adding a callout on the issues of using attach/detach vs. using with()

Thanks for the suggestion.

Rob

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff