[Rd] Strange R object

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 08 Jul 2010 23:05:23 -0400


I have *** attached *** an RData file containing an R object that is acting strangely.

Try this in a fresh workspace. Do not load zoo or any other package. We load the object, zz2, from the attached RData file. It is just the number 1 with the class c("zooreg", "zoo").

Now create an S3 print routine that simply prints an X when given an object of class "zoo".

If we use print on the object it produces an X but not if we just enter it at the console. Also the object is not identical to its dput output.

How can such an object exist? What is it about the object that is different from structure(1, class = c("zoo", "zooreg")) ?

> # load problem object, zz2
> load("problem.RData")
>
> # examine it. Its very simple.
> dput(zz2)

structure(1, class = c("zooreg", "zoo"))
>
> # define a print routine to intercept it
> print.zoo <- function(x, ...) print("X")
>
> # the print routine works as expected
> print(zz2)

[1] "X"
>
> # but not if we use implicit printing!
> zz2

[1] 1
attr(,"class")
>
>
> # I would have expected that the last statement produce an "X" too!
> ###################################################################
>
> # these have the same dput output but are not identical!
> # I would have expected them to be the identical.
> ###################################################################
> aa2 <- structure(1, class = c("zooreg", "zoo"))
> dput(aa2)

structure(1, class = c("zooreg", "zoo"))
> dput(zz2)

structure(1, class = c("zooreg", "zoo"))
> identical(aa2, zz2)

[1] FALSE
> sessionInfo()

R version 2.11.1 Patched (2010-05-31 r52167) i386-pc-mingw32

locale:

[1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252
[3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

P.S. I also get the same thing under:

> R.version.string

[1] "R version 2.12.0 Under development (unstable) (2010-05-31 r52164)"



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 09 Jul 2010 - 03:07:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 09 Jul 2010 - 11:00:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive