Skip to content

problems with assigning a class to an environment

2 messages · Jens Oehlschlägel, Peter Dalgaard

#
I was surprised to find that calling str() on an environment can remove
attributes from it, as in
[1] "jens"
Class 'jens' length 0 <environment>
NULL

then I found in the R-Language-Manual in chapter 2.1.10 Environments the
sentence: 

	"In particular, assigning attributes to an environment can lead to
surprises"

Can please someone familiar with the internals explain what's going on?

Is it save, to assign a class to a list which contains an environment?


Thank you


Jens Oehlschl?gel
_              
platform i386-pc-mingw32
arch     i386           
os       Win32          
system   i386, mingw32  
status                  
major    1              
minor    5.1            
year     2002           
month    06             
day      17             
language R
#
Jens Oehlschl?gel <joehl at gmx.de> writes:
The main issue is that environments aren't copied on assignment, so
stuff like y <- unclass(x) will remove the class attribute from x if x
is an environment. Or, as is the case here, str(unclass(x)) will do it.
Yes, and the recommended way.