Seeing Global Workspace and dealing with attach and detach

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Seeing Global Workspace and dealing with attach and detach

David Arnold
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.
Reply | Threaded
Open this post in threaded view
|

Re: Seeing Global Workspace and dealing with attach and detach

Jeff Newmiller
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:<[hidden email]>        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 <[hidden email]> 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.
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Seeing Global Workspace and dealing with attach and detach

bbolker
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"]

______________________________________________
[hidden email] 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.