John Chambers
2009-Feb-16 23:54 UTC
[Rd] Inheriting from "environment" and similar object types
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. John
Reasonably Related Threads
- `@<-` modify its argument when slot is externalptr
- Questions on version arg to setClass and serialized instances
- For integer vectors, `as(x, "numeric")` has no effect.
- For integer vectors, `as(x, "numeric")` has no effect.
- [Bioc-devel] For integer vectors, `as(x, "numeric")` has no effect.