[R] problems with assigning a class to an environment
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Mon Jun 24 23:43:25 CEST 2002
Jens Oehlschlägel <joehl at gmx.de> writes:
> I was surprised to find that calling str() on an environment can remove
> attributes from it, as in
>
> > a <- new.env()
> > class(a) <- "jens"
> > class(a)
> [1] "jens"
> > str(a)
> Class 'jens' length 0 <environment>
> > class(a)
> 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?
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.
> Is it save, to assign a class to a list which contains an environment?
Yes, and the recommended way.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list