Skip to content
Prev 26318 / 63424 Next

R 2.6.0 S4 data breakage, R _data_class(), class<-, etc.

Most of your problems seem related to assigning an S4 class to an 
arbitrary object--a really bad idea, since it can produce invalid objects.

Objects from S4 classes are created by calling the function new(), and 
in principal _only_ by calling that function.  Objects from one class 
are coerced to another by calling the function as().

Assigning a class to any old object is a very S3 idea (and not a good 
idea except in low-level code there, either).

At the C level there are  macros for new() (R recommends NEW_OBJECT()), 
although the safest approach when feasible is to allocate the object in 
R.  The general as() computation really needs to be done in R because of 
its special use of method dispatch; there are macros for the equivalent 
of the as.<type>() functions.

Perhaps some improvements to the documentation would make this clearer, 
although Chapter 7 and Appendix A of Programming with Data seem 
reasonably definite.

Thanks for sharing your notes.

John
Hin-Tak Leung wrote:
Yes, or at the least instructions to handle the case of a NULL class 
attribute, but a macro would be good.