[Rd] Inheriting from "environment" and similar object types

From: John Chambers <jmc_at_r-project.org>
Date: Mon, 16 Feb 2009 15:54:28 -0800

Attributes can't be assigned to objects of type "environment" or similar types such as external pointers or names (symbols). The objects are references, not normal R objects, and are not copied by the internal duplicate() routine, so any attribute (including "class") overwrites the same object. This means that classes, either S4 or S3, can't inherit from these types directly.

A mechanism has been added to r-devel (version r47933) that allows S4 classes to contain "environment" and similar types. The mechanism uses a reserved slot name to hold the reference. Code in various places recognizes S4 objects with this slot and coerces the object to the corresponding type. See ?setClass.

The mechanism is transparent for quite a few computations, but there can't be a full guarantee, since low-level code can operate directly using the object type, which of course will not correspond to
"environment". Usually, a workaround is to pass in as(object,
"environment") instead of object.

The same mechanism is used to allow extending "externalptr" and "name", and other similar types will likely be added after some more testing.

Details of the mechanism are still experimental, and may change.


R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 16 Feb 2009 - 22:57:24 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 Tue 17 Feb 2009 - 07:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive