[Rd] changes in r-devel for S3/S4 objects

From: John Chambers <jmc_at_r-project.org>
Date: Mon 20 Feb 2006 - 22:03:32 GMT


Two recent changes have been committed to r-devel, related to discussions on this list earlier:

  1. setOldClass() has an argument prototype= to specify the default object for the class. If provided, the S3 class can be a slot in an S4 class, with a valid default object.

(It's still not going to work well to have an S3 non-virtual class as a
superclass of an S4 class. See the setOldClass help page.)

2. There is a heuristic test for S4 objects, seemsS4Object(), and a corresponding C-level test, R_seemsS4Object(object), both using the existence of a "package" attribute on class(object) as a test.

The test is called seemsS4Object() rather than isS4Object() deliberately, but it should be fairly accurate.

It will mistakenly identify an S3 object as S4 if the package attribute is there (possible, but hard to see why anyone would do this). It can make the opposite mistake, though, UNLESS the package generating the object is reinstalled with the current version of R, because older versions failed to put the attribute on some of the basic S4 classes
(esp. classRepresentation).

This is not by itself the right test for intercepting S3 code for certain primitives (c(), match(), [, for example), as was being discussed earlier. Only S4 objects that do not inherit from "vector" should be blocked. So the suitable test, in R code, is something like:   if(seemsS4Object(x) && !is(x, "vector"))



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Feb 21 09:50:20 2006

This archive was generated by hypermail 2.1.8 : Tue 21 Feb 2006 - 03:44:41 GMT