[R] Objects within environment

Duncan Murdoch murdoch.duncan at gmail.com
Wed Jul 21 18:45:51 CEST 2010


On 21/07/2010 12:27 PM, Megh Dal wrote:
> Hi Duncan, thanks for your clarification. However I do not think I could really understand the "envir" argument in objects() function.....
>
> It is saying "an alternative argument for name........" Is the "alternative" means the alternative of, let say, "package:graphics" (which is the name of an environment?). Can you give me an example of an alternative argument of that particular environment?
>   

as.environment("package:graphics") is an environment.  
"package:graphics" is its name.
> This is "specifying the environment evaluation environment." What does the phase "environment evaluation environment" mean? Can you give me an example?
>   

That looks like a typo to me.  "Environment evaluation environment" is 
meaningless.
> "Mostly there for back compatibility": again totally in dark, what does it mean for "back compatibility?" An example would definitely be great.
>   

Presumably some older release of R used envir, and we still have it so 
that old code will still work.  But that's a signal that new code should 
never need to use it.
> Toy said "you need to give an environment, not the name of one". If I call someone I need to call with his name, right? Then if I need to give an environment then, without its name how can I do so?
>   

This is a computer language, not a conversation.  Words have technical 
meanings that aren't always perfect matches to English meanings of the 
same words.  Here the "name" of an environment is what you get when you 
ask for the "name" attribute of it.  There are lots of different ways to 
refer to objects other than by the "name" in that technical sense.  For 
example, you could say

x <- as.environment("package:graphics") # uses the environment's "name"
ls(envir=x) # refers to it by a variable holding it.

Duncan Murdoch
> Can you please explain me in simple english? I think R help file should use more non-technical simple english language so that student like me can understand R in more easier way!
>
> --- On Wed, 7/21/10, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>
> > From: Duncan Murdoch <murdoch.duncan at gmail.com>
> > Subject: Re: [R] Objects within environment
> > To: "Megh Dal" <megh700004 at yahoo.com>
> > Cc: r-help at stat.math.ethz.ch
> > Date: Wednesday, July 21, 2010, 4:48 PM
> > On 21/07/2010 5:57 AM, Megh Dal
> > wrote:
> > > Hi all, I have following environments loaded with my
> > current R session:
> > > 
> > >> search()
> > > [1] ".GlobalEnv"       
> > "package:stats" 
> >    "package:graphics" 
> > "package:grDevices"
> > > [5] "package:utils" 
> >    "package:datasets" 
> > "package:methods"   "Autoloads"   
> >     [9] "package:base"    
> > > How can I find the objects under a specific
> > environment? Here I tries following:
> > > 
> > >> objects(envir="package:base")
> > > Error in objects(envir = "package:base") : invalid
> > 'envir' argument
> > > 
> > > It would be great if somebody would point me the
> > correct arguments for object() function to find the onjects
> > associated with it. In help file it is written that:
> > > " envir: an alternative argument to ‘name’ for
> > specifying the
> > >       
> >    environment evaluation environment. Mostly
> > there for back
> > >       
> >    compatibility"
> > > What is the wrong in my code?
> > 
> > The easiest way to pick an item from the search list is by
> > number:
> > 
> > objects(3)
> >  or
> > ls(3)
> > 
> > will give you the objects in the graphics package, with the
> > search list as above.  You can also specify the name as
> > the name argument, e.g.
> > 
> > objects("package:base")
> > 
> > If you want to use the envir argument (why?), you need to
> > give an environment, not the name of one.
> > 
> > Duncan Murdoch
> > 
> > 
>
>
>       
>



More information about the R-help mailing list