Skip to content
Prev 37113 / 63421 Next

Strange R object

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")) ?
structure(1, class = c("zooreg", "zoo"))
[1] "X"
[1] 1
attr(,"class")
structure(1, class = c("zooreg", "zoo"))
structure(1, class = c("zooreg", "zoo"))
[1] FALSE
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:
[1] "R version 2.12.0 Under development (unstable) (2010-05-31 r52164)"