Jens Oehlschlägel
2002-Jun-24 19:14 UTC
[R] problems with assigning a class to an environment
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? Is it save, to assign a class to a list which contains an environment? Thank you Jens Oehlschl?gel> version_ 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 -- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2002-Jun-24 21:43 UTC
[R] problems with assigning a class to an environment
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Apparently Analagous Threads
- file.rename overwrites existing target (PR#14065)
- basename returns "." not in filename (PR#13958)
- please help with estimation of true correlations andreliabilities
- How to grow an R object from C (.Call Interface)
- Error in substring: invalid multibyte string