From ripley at stats.ox.ac.uk  Tue Nov 23 16:22:13 2004
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Tue Nov 23 16:22:34 2004
Subject: [Rd] str() resets class for environments
In-Reply-To: <41A345B9.4070104@jhsph.edu>
References: <41A345B9.4070104@jhsph.edu>
Message-ID: <Pine.LNX.4.61.0411231448350.27627@gannet.stats>

On Tue, 23 Nov 2004, Roger D. Peng wrote:

> I noticed the following today --- str() seems to remove any extra class 
> information added to an environment.
>
>> e <- new.env()
>> class(e)
> [1] "environment"
>> class(e) <- c("foo", class(e))
>> class(e)
> [1] "foo"         "environment"
>> str(e)
> Classes 'foo', 'environment' length 0 <environment>
>> class(e)
> [1] "environment"
>
> I'm not sure if this is related to the external pointer issue mentioned in 
> the NEWS file.

It is.  Needed essentially the same fix.

> Is this the intended behavior for environments?  (It happens 
> in today's R-devel also.)

I believe the intention is that you should not class environments. Luke 
suggested earlier that unclassing one be made an error, and I have now 
done that.  Note that environments are not copied, and so everything you 
do to one instance you do to all other instances of it.  Setting a class 
makes little sense for such an object.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] str() resets class for environments
Prof Brian Ripley