Re: [Rd] Strange R object

From: Peter Dalgaard <>
Date: Fri, 09 Jul 2010 11:09:58 +0200

Gabor Grothendieck wrote:
> 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")) ?

There's a bit in the SEXP structure that is supposed to be turned on when an object has an S3 class. This is where implicit print looks, whereas explicit print looks, er, elsewhere. Notice that

> is.object(zz2)

> class(zz2) <- class(zz2)
> zz2

> is.object(zz2)

[1] TRUE Whenever the same information is stored in two ways, there is a risk of inconsistency, so it is not too strange that you can have an ill-formed .Rdata file (if you save zz2 back out, after the above fixup, line 11 changes from 526 to 782, corresponding to the bit being turned on).

I don't think it is the job of load() to verify object structures, since there is no end to that task. Rather, we shouldn't create them in the first place, but you give us no clues as to how that object got made.

Peter Dalgaard
Center for Statistics, Copenhagen Business School
Phone: (+45)38153501
Email:  Priv:

______________________________________________ mailing list
Received on Fri 09 Jul 2010 - 09:12:36 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 - 12:30:13 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive