Re: [R] Where did lost variables go

2014-01-02 Thread jwd
On Mon, 30 Dec 2013 20:42:53 -0500
David Parkhurst parkh...@indiana.edu wrote:

 I have several variables in a data frame that aren't listed by ls() 
 after I attach that data frame.  Where did they go, and how can I
 stop the hidden ones from masking the local ones?
 Thanks for any help.
 David
 
You really need to offer more information, e.g. a reproducible example
that includes just how how moved data into your data frame. As
it is, the only reasonable suggestion is to try and find your lost
singleton socks, the missing variablee may be hiding with them.
Alternatively the lost variables may have taken off to Never Never Land
to hang with the Lost Boys.

One simple possibility is that the missing variables were actually
never read in to the data frame.  Have you ever seen those variables
in your data frame?  Did you try str(dataframe)?

As regards hidden and local, you'll - again - have to be a good
deal more explicit.  

JDougherty

__
R-help@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.


Re: [R] Where did lost variables go, with example

2014-01-02 Thread PIKAL Petr
Hi

you are confusing yourself and maybe other audience.

With ls() you list objects in your environment (usually stored in .RData file) 
and loaded with starting R.

Let me guess. You probably have 2 data frames All8 and All8Sites. They have 
some variables inside and you can see structure of any object by str

str(All8)

you can see names of these variables by names

names(All8)

you can use those variables by e.g.

All8Sites$X

You probably managed somehow to save variables from data.frame to independent 
objects in your environment, which can be confusing.

Maybe it is time to read R-intro which is located in doc folder of your R 
installation.
Regards
Petr



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of David Parkhurst
 Sent: Tuesday, December 31, 2013 5:39 PM
 To: Duncan Murdoch; r-help@r-project.org
 Subject: Re: [R] Where did lost variables go, with example
 
 Thank you.  I've tried what you're suggesting, at an earlier suggestion
 from another respondent, and I don't find my variable in any of lists
 ls() through ls(7).
 
 I'm just going back to using R after being away from statistics for
 several years.  I'm thinking I might uninstall R, then reinstall it,
 and redo my work so far (I've kept the commands elsewhere), and avoid
 using attach, as someone else has suggested.
 
 David
 On 12/31/2013 11:32 AM, Duncan Murdoch wrote:
  On 13-12-31 9:48 AM, David Parkhurst wrote:
  Two or three respondents asked for an example of my problem.  Here's
  what's happening to me now.  I can't reproduce how I got to this
  point,
  though:
 
 ls()
  [1] All8   All8Sites  A   B  C  i  n  D  F
 X
  Error: object 'X' not found
 attach(All8Sites)
 ls()
  [1] All8  All8Sites  A  B  C  i  n  D  F
 
 
  X is one of the variables in the data frame I attached in the
 third
  command above, but it's not listed by ls().  If I enter  X now,
 its
  values ARE listed, but it's hiding somewhere.  What is happening
 here?
  How can I get the variables in that data frame listed when I attach
 it?
 
  Use search() to see the search list.  Your dataframe will likely be
 in
  position 2.  Use ls(2) to see the variables there.
 
  Duncan Murdoch
 
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@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.

__
R-help@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.


Re: [R] Where did lost variables go, with example

2014-01-02 Thread peter dalgaard

On 31 Dec 2013, at 17:32 , Duncan Murdoch murdoch.dun...@gmail.com wrote:

 On 13-12-31 9:48 AM, David Parkhurst wrote:
 Two or three respondents asked for an example of my problem.  Here's
 what's happening to me now.  I can't reproduce how I got to this point,
 though:
 
   ls()
 [1] All8   All8Sites  A   B  C  i  n  D  F
   X
 Error: object 'X' not found
   attach(All8Sites)
   ls()
 [1] All8  All8Sites  A  B  C  i  n  D  F
 
 
 X is one of the variables in the data frame I attached in the third
 command above, but it's not listed by ls().  If I enter  X now, its
 values ARE listed, but it's hiding somewhere.  What is happening here?
 How can I get the variables in that data frame listed when I attach it?
 
 Use search() to see the search list.  Your dataframe will likely be in 
 position 2.  Use ls(2) to see the variables there.

Or ls(All8Sites). Notice, by the way, that this is subtly but importantly 
different from ls(All8Sites). E.g.,


 attach(airquality)
 ls(2)
[1] Day Month   Ozone   Solar.R TempWind   
 ls(airquality)
[1] Day Month   Ozone   Solar.R TempWind   
 search()
 [1] .GlobalEnvairqualitypackage:stats
 [4] package:graphics  package:grDevices package:utils
 [7] package:datasets  package:methods   Autoloads
[10] package:base 
 ls(airquality)
[1] Day Month   Ozone   Solar.R TempWind   
 rm(Month, pos=2)
 ls(airquality)
[1] Day Month   Ozone   Solar.R TempWind   
 ls(airquality)
[1] Day Ozone   Solar.R TempWind   
 detach()
 ls(airquality)
Error in as.environment(pos) : 
  no item called airquality on the search list


-pd

 
 Duncan Murdoch
 
 __
 R-help@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.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@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.


[R] Where did lost variables go

2013-12-31 Thread David Parkhurst
I have several variables in a data frame that aren't listed by ls() 
after I attach that data frame.  Where did they go, and how can I stop 
the hidden ones from masking the local ones?
Thanks for any help.
David

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Where did lost variables go

2013-12-31 Thread Simon Zehnder
A reproducible example would do well here David

Best

Simon
On 31 Dec 2013, at 02:42, David Parkhurst parkh...@indiana.edu wrote:

 I have several variables in a data frame that aren't listed by ls() 
 after I attach that data frame.  Where did they go, and how can I stop 
 the hidden ones from masking the local ones?
 Thanks for any help.
 David
 
   [[alternative HTML version deleted]]
 
 __
 R-help@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.

__
R-help@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.


Re: [R] Where did lost variables go

2013-12-31 Thread Berwin A Turlach
G'day David,

On Mon, 30 Dec 2013 20:42:53 -0500
David Parkhurst parkh...@indiana.edu wrote:

Some wild guesses in the absence of a reproducible example.

 I have several variables in a data frame that aren't listed by ls() 
 after I attach that data frame. 

ls() list the objects in the global environment.  If you attach a data
frame it is attached to the search path, typically after the global
environment.  

Type 'search()' to see your search path.

ls() list the global environment, the first entry in the list and
called .GlobalEnv.  Your data frame should be listed as an object in
that environment.  

Assuming the name of your data frame is 'foo', then there should be the
name 'foo' somewhere in the list of names returned by 'search()'.
Assuming 'foo' is listed in the second position, then 'ls(2)' should
list all the objects found at that location of the search path, i.e.
all the variables in your data frame.

 Where did they go, 

See above.

 and how can I stop the hidden ones from masking the local ones?

Do you mean with local ones those in the global environment and by
hidden ones those that you couldn't find?  I.e. is there an object
bar listed by 'ls()' but also an object bar listed by 'ls(2)' (i.e.
your data frame 'foo' contained a variable with name 'bar')?  Then it is
the other way round, the local ones are hiding the hidden ones.  

For that reason attaching data frames has its dangers.  It allows to
easily access the variables in the data frame, but any changes to a
variable creates a local copy.  Thus, any change *will* not propagate
back to the data frame!  

Hopefully the commands below will clarify further.

Cheers,

Berwin


R foo - data.frame(bar=rnorm(2), fubar=runif(2))
R ls()
[1] foo
R attach(foo)
R search()
 [1] .GlobalEnvfoo   package:stats
 [4] package:graphics  package:grDevices package:utils
 [7] package:datasets  package:methods   Autoloads
[10] package:base 
R ls(2)
[1] bar   fubar
R bar
[1] -0.07741633  1.05804653
R fubar
[1] 0.08516929 0.82718383
R bar - what now
R ls()
[1] bar foo
R bar
[1] what now
R ls(2)
[1] bar   fubar
R get(bar, pos=2)
[1] -0.07741633  1.05804653
R foo
  bar  fubar
1 -0.07741633 0.08516929
2  1.05804653 0.82718383
R detach(2)
R bar
[1] what now
R fubar
Error: object 'fubar' not found
R foo
  bar  fubar
1 -0.07741633 0.08516929
2  1.05804653 0.82718383
R attach(foo)
The following object is masked _by_ .GlobalEnv:

bar
R bar
[1] what now
R fubar
[1] 0.08516929 0.82718383
R detach(2)
R bar
[1] what now
R fubar
Error: object 'fubar' not found
R foo
  bar  fubar
1 -0.07741633 0.08516929
2  1.05804653 0.82718383

__
R-help@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.


Re: [R] Where did lost variables go

2013-12-31 Thread Bert Gunter
Gents:

I would add that:

1) attach() should probably no longer be used in R, for all the
reasons (and more) cited,

2)  The preferred alternative these days is to use lists, including
data frames, as containers and make liberal use of the  ?with and
?within  functions. Environments can also be useful, but are more
complicated as their semantics differ. S4 classes and objects are
probably also relevant.

Comments, criticisms, links, additions, and subtractions welcome, as
this issue comes up regularly here and it would be nice to have
consensus wisdom to refer to.

Cheers,


Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
H. Gilbert Welch




On Tue, Dec 31, 2013 at 2:14 AM, Berwin A Turlach
berwin.turl...@gmail.com wrote:
 G'day David,

 On Mon, 30 Dec 2013 20:42:53 -0500
 David Parkhurst parkh...@indiana.edu wrote:

 Some wild guesses in the absence of a reproducible example.

 I have several variables in a data frame that aren't listed by ls()
 after I attach that data frame.

 ls() list the objects in the global environment.  If you attach a data
 frame it is attached to the search path, typically after the global
 environment.

 Type 'search()' to see your search path.

 ls() list the global environment, the first entry in the list and
 called .GlobalEnv.  Your data frame should be listed as an object in
 that environment.

 Assuming the name of your data frame is 'foo', then there should be the
 name 'foo' somewhere in the list of names returned by 'search()'.
 Assuming 'foo' is listed in the second position, then 'ls(2)' should
 list all the objects found at that location of the search path, i.e.
 all the variables in your data frame.

 Where did they go,

 See above.

 and how can I stop the hidden ones from masking the local ones?

 Do you mean with local ones those in the global environment and by
 hidden ones those that you couldn't find?  I.e. is there an object
 bar listed by 'ls()' but also an object bar listed by 'ls(2)' (i.e.
 your data frame 'foo' contained a variable with name 'bar')?  Then it is
 the other way round, the local ones are hiding the hidden ones.

 For that reason attaching data frames has its dangers.  It allows to
 easily access the variables in the data frame, but any changes to a
 variable creates a local copy.  Thus, any change *will* not propagate
 back to the data frame!

 Hopefully the commands below will clarify further.

 Cheers,

 Berwin


 R foo - data.frame(bar=rnorm(2), fubar=runif(2))
 R ls()
 [1] foo
 R attach(foo)
 R search()
  [1] .GlobalEnvfoo   package:stats
  [4] package:graphics  package:grDevices package:utils
  [7] package:datasets  package:methods   Autoloads
 [10] package:base
 R ls(2)
 [1] bar   fubar
 R bar
 [1] -0.07741633  1.05804653
 R fubar
 [1] 0.08516929 0.82718383
 R bar - what now
 R ls()
 [1] bar foo
 R bar
 [1] what now
 R ls(2)
 [1] bar   fubar
 R get(bar, pos=2)
 [1] -0.07741633  1.05804653
 R foo
   bar  fubar
 1 -0.07741633 0.08516929
 2  1.05804653 0.82718383
 R detach(2)
 R bar
 [1] what now
 R fubar
 Error: object 'fubar' not found
 R foo
   bar  fubar
 1 -0.07741633 0.08516929
 2  1.05804653 0.82718383
 R attach(foo)
 The following object is masked _by_ .GlobalEnv:

 bar
 R bar
 [1] what now
 R fubar
 [1] 0.08516929 0.82718383
 R detach(2)
 R bar
 [1] what now
 R fubar
 Error: object 'fubar' not found
 R foo
   bar  fubar
 1 -0.07741633 0.08516929
 2  1.05804653 0.82718383

 __
 R-help@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.

__
R-help@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.


Re: [R] Where did lost variables go, with example

2013-12-31 Thread David Parkhurst
Two or three respondents asked for an example of my problem.  Here's 
what's happening to me now.  I can't reproduce how I got to this point, 
though:

  ls()
[1] All8   All8Sites  A   B  C  i  n  D  F
  X
Error: object 'X' not found
  attach(All8Sites)
  ls()
[1] All8  All8Sites  A  B  C  i  n  D  F


X is one of the variables in the data frame I attached in the third 
command above, but it's not listed by ls().  If I enter  X now, its 
values ARE listed, but it's hiding somewhere.  What is happening here?  
How can I get the variables in that data frame listed when I attach it?

Thanks to all.
David


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Where did lost variables go, with example

2013-12-31 Thread Duncan Murdoch

On 13-12-31 9:48 AM, David Parkhurst wrote:

Two or three respondents asked for an example of my problem.  Here's
what's happening to me now.  I can't reproduce how I got to this point,
though:

   ls()
[1] All8   All8Sites  A   B  C  i  n  D  F
   X
Error: object 'X' not found
   attach(All8Sites)
   ls()
[1] All8  All8Sites  A  B  C  i  n  D  F


X is one of the variables in the data frame I attached in the third
command above, but it's not listed by ls().  If I enter  X now, its
values ARE listed, but it's hiding somewhere.  What is happening here?
How can I get the variables in that data frame listed when I attach it?


Use search() to see the search list.  Your dataframe will likely be in 
position 2.  Use ls(2) to see the variables there.


Duncan Murdoch

__
R-help@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.


Re: [R] Where did lost variables go, with example

2013-12-31 Thread Duncan Murdoch

On 13-12-31 11:38 AM, David Parkhurst wrote:

Thank you.  I've tried what you're suggesting, at an earlier suggestion
from another respondent, and I don't find my variable in any of lists
ls() through ls(7).


Are you sure that X is really the name of a column in the dataframe? 
names(All8Sites) will tell you all the names that are there.




I'm just going back to using R after being away from statistics for
several years.  I'm thinking I might uninstall R, then reinstall it, and
redo my work so far (I've kept the commands elsewhere), and avoid using
attach, as someone else has suggested.


It's not likely to be necessary to reinstall R, but it shouldn't hurt.

Duncan Murdoch



David
On 12/31/2013 11:32 AM, Duncan Murdoch wrote:

On 13-12-31 9:48 AM, David Parkhurst wrote:

Two or three respondents asked for an example of my problem.  Here's
what's happening to me now.  I can't reproduce how I got to this point,
though:

   ls()
[1] All8   All8Sites  A   B  C  i  n  D  F
   X
Error: object 'X' not found
   attach(All8Sites)
   ls()
[1] All8  All8Sites  A  B  C  i  n  D  F


X is one of the variables in the data frame I attached in the third
command above, but it's not listed by ls().  If I enter  X now, its
values ARE listed, but it's hiding somewhere.  What is happening here?
How can I get the variables in that data frame listed when I attach it?


Use search() to see the search list.  Your dataframe will likely be in
position 2.  Use ls(2) to see the variables there.

Duncan Murdoch





__
R-help@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.


Re: [R] Where did lost variables go, with example

2013-12-31 Thread David Parkhurst
Thank you.  I've tried what you're suggesting, at an earlier suggestion 
from another respondent, and I don't find my variable in any of lists 
ls() through ls(7).

I'm just going back to using R after being away from statistics for 
several years.  I'm thinking I might uninstall R, then reinstall it, and 
redo my work so far (I've kept the commands elsewhere), and avoid using 
attach, as someone else has suggested.

David
On 12/31/2013 11:32 AM, Duncan Murdoch wrote:
 On 13-12-31 9:48 AM, David Parkhurst wrote:
 Two or three respondents asked for an example of my problem.  Here's
 what's happening to me now.  I can't reproduce how I got to this point,
 though:

ls()
 [1] All8   All8Sites  A   B  C  i  n  D  F
X
 Error: object 'X' not found
attach(All8Sites)
ls()
 [1] All8  All8Sites  A  B  C  i  n  D  F


 X is one of the variables in the data frame I attached in the third
 command above, but it's not listed by ls().  If I enter  X now, its
 values ARE listed, but it's hiding somewhere.  What is happening here?
 How can I get the variables in that data frame listed when I attach it?

 Use search() to see the search list.  Your dataframe will likely be in 
 position 2.  Use ls(2) to see the variables there.

 Duncan Murdoch



[[alternative HTML version deleted]]

__
R-help@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.