[Rd] Destructive str(...)?

From: Simon Urbanek <simon.urbanek_at_math.uni-augsburg.de>
Date: Sat 30 Oct 2004 - 13:28:54 EST


I have encountered a strange behavior of the str function - it seems to modify the object that is displayed. Probably I'm using something unsupported (objects consisting just of an external reference), but still I'm curious as of why this happens. I create (in C code) EXTPTRSXP and associate a class to it via SET_CLASS. Such objects works fine until it's passed to str as the following output demonstrates:

> c<-.MCall("RController","getRController")
> c

[1] "<RController: 0x3be5d0>"
> str(c)

Class 'ObjCid' length 1 <pointer: 0x3be5d0>
> c

<pointer: 0x3be5d0>
> str(c)

length 1 <pointer: 0x3be5d0>

The .MCall basically produces an external reference and assigns a class (ObjCid) to it. There's a corresponding print method and it works fine. However, when str is called, it strips the class information from the object as a repeated call to str also shows:

  > str(c); str(c)
Class 'ObjCid' length 1 <pointer: 0x3be5d0> length 1 <pointer: 0x3be5d0>

Is this behavior intentional, undocumented or simply wrong?

Cheers,
Simon

[Tested with R 2.0.0 release (2004-10-04) on Mac OS X 10.3.5 - I have currently no other machine to test it on, but I very much suspect that this is platform-independent.]

the C code used to generate the object:

SEXP class, sref = R_MakeExternalPtr((void*) obj, R_NilValue, R_NilValue);
PROTECT(class = allocVector(STRSXP, 1)); SET_STRING_ELT(class, 0, mkChar("ObjCid")); SET_CLASS(sref, class);
UNPROTECT(1);



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Oct 30 13:35:14 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:00:58 EST