In the code below, e is an environment which we copy to f and then add attributes to e. Now f winds up with the same attributes. In other words it seems that the attributes are a property of the environment itself and not of the variable. Thus it appears we cannot have two environment variables that correspond to the original environment but with different attributes. I can understand if we changed a component of e then f would reflect that too but I am not sure that this is also desirable for attributes as they are not "in" the environment. Is that desirable? Is it a bug? No other class works that way AFAIK. Comments?> e <- new.env() > f <- e > attr(e, "X") <- "Y" # X is an attribute of e > f # f gets the same attribute !!!<environment: 0x01a577f0> attr(,"X") [1] "Y"> R.version.string # Windows XP[1] "R version 2.4.0 Under development (unstable) (2006-07-04 r38480)"
On 7/4/2006 11:12 PM, Gabor Grothendieck wrote:> In the code below, e is an environment which we copy to f and then > add attributes to e. Now f winds up with the same attributes. > > In other words it seems that the attributes are a property of the > environment itself and not of the variable. Thus it appears we > cannot have two environment variables that correspond to the > original environment but with different attributes. > > I can understand if we changed a component of e then > f would reflect that too but I am not sure that this is also > desirable for attributes as they are not "in" the environment. > > Is that desirable? Is it a bug? No other class works that way > AFAIK. Comments?I'm not sure about whether this is desirable or a bug, but environments are special, in that they are among the very few objects treated as references. In your example, adding a variable to e will also make it visible in f. Duncan Murdoch> >> e <- new.env() >> f <- e >> attr(e, "X") <- "Y" # X is an attribute of e >> f # f gets the same attribute !!! > <environment: 0x01a577f0> > attr(,"X") > [1] "Y" >> R.version.string # Windows XP > [1] "R version 2.4.0 Under development (unstable) (2006-07-04 r38480)" > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
On Tue, 4 Jul 2006, Gabor Grothendieck wrote:> In the code below, e is an environment which we copy to f and then > add attributes to e. Now f winds up with the same attributes. > > In other words it seems that the attributes are a property of the > environment itself and not of the variable. Thus it appears we > cannot have two environment variables that correspond to the > original environment but with different attributes.No, we can't. The two variables are references to the same environment, so they are the same. If you want the attributes to be copies rather than references then create a list with the environment as an element and put the attributes on the list. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Maybe Matching Threads
- Attributes of top level environments clobbered (was Re: [R] possible bug in function 'var' in R 2.7.2?)
- terminology for frames and environments
- plot, spineplot, boxplot in R 2.2.0
- Stacked plots with common x-axis and different y-axis
- Summary: do.call and environments