[Rd] Strange R object
pdalgd at gmail.com
Fri Jul 9 11:09:58 CEST 2010
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
> class(zz2) <- class(zz2)
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.
Center for Statistics, Copenhagen Business School
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-devel