From tlumley at u.washington.edu  Wed Jul  5 18:17:55 2006
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Wed, 5 Jul 2006 09:17:55 -0700 (PDT)
Subject: [Rd] attributes of environments
In-Reply-To: <971536df0607050910w2a35e6ecxef5dec5c41a781e3@mail.gmail.com>
References: <971536df0607042012h43eb1581n418e9cddfe3a51bb@mail.gmail.com> 
	<Pine.LNX.4.64.0607050857440.32591@homer22.u.washington.edu>
	<971536df0607050910w2a35e6ecxef5dec5c41a781e3@mail.gmail.com>
Message-ID: <Pine.LNX.4.64.0607050911380.32591@homer22.u.washington.edu>

On Wed, 5 Jul 2006, Gabor Grothendieck wrote:

> On 7/5/06, Thomas Lumley <tlumley at u.washington.edu> wrote:
>> 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.
>
> I realize that that is how it works but what I was really wondering was
> should it work that way?
>

I think it really should (and this question has come up before).  If you 
do
    e<-environment()
    f<-e

then there is only one object that f and e both point to. Now, since such 
things as S3 class and matrix dimension are implemented as attributes I 
think you really have to consider the attributes as part of the object 
[which is also how they are implemented, of course].  So if e and f are 
the same object they should have the same attributes.

Another reasonable position would be to disallow attributes on 
environments (as we do with NULL, another reference object), but that 
seems extreme.

 	-thomas



[Rd] attributes of environments
Thomas Lumley