Hi, When writing a script, I often start with: library(ISwR) attach(thuesen) Then write some more code, testing it as I write to see if it runs. Then, at the end, a final: detach(thuesen) However, what happens is that I often get errors, which cause an attach, but no subsequent detach. Now, I can fix the problem at the console window with several: detach(thuesen) detach(thuesen) detach(thuesen) detach(thuesen) detach(thuesen) Until they are finally all closed. Two questions: 1. What is a more efficient method? 2. What is the command again for viewing the global workspace? D. -- View this message in context: http://r.789695.n4.nabble.com/Seeing-Global-Workspace-and-dealing-with-attach-and-detach-tp4659105.html Sent from the R help mailing list archive at Nabble.com.
Seeing Global Workspace and dealing with attach and detach
3 messages · David Arnold, Jeff Newmiller, Ben Bolker
In general, creating variables while attached leads to problems such as you describe. Normally the recommendation is to avoid the use of attach and detach entirely in favor of explicit reference to the data frame using [[]], [,], $, and the data= argument supported by many functions.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
David Arnold <dwarnold45 at suddenlink.net> wrote:
Hi, When writing a script, I often start with: library(ISwR) attach(thuesen) Then write some more code, testing it as I write to see if it runs. Then, at the end, a final: detach(thuesen) However, what happens is that I often get errors, which cause an attach, but no subsequent detach. Now, I can fix the problem at the console window with several: detach(thuesen) detach(thuesen) detach(thuesen) detach(thuesen) detach(thuesen) Until they are finally all closed. Two questions: 1. What is a more efficient method? 2. What is the command again for viewing the global workspace? D. -- View this message in context: http://r.789695.n4.nabble.com/Seeing-Global-Workspace-and-dealing-with-attach-and-detach-tp4659105.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Jeff Newmiller <jdnewmil <at> dcn.davis.ca.us> writes:
In general, creating variables while attached leads to problems such as you describe. Normally the recommendation is to avoid the use of attach and detach entirely in favor of explicit reference to the data frame using [[]], [,], $, and the data= argument supported by many functions.
And with() and within() [as well as transform(), mutate(), subset(), etc.: see http://r4stats.com/2013/01/22/comparing-tranformation-styles/ [sic "tranformation"]