Skip to content
Prev 17016 / 63424 Next

S4 Dispatching

Paul Roebuck wrote:
That is definitely a problem in the current R implementation.

Because external pointers (and environments and some other data types) 
are not duplicated in the way that ordinary vectors are, you cannot 
directly extend them as a class.  You can't for example set the class of 
such an object without affecting all the other code that uses the same 
pointer.

The usual workaround is to define a list of one element that contains 
the external pointer, and make that the object.  Or equivalently set up 
an S4 class with the external pointer as a slot.  That's not a really 
satisfactory workaround, though, since it's not what was intended.

It would be nice if the implementation duplicated the attributes, if 
any, of such objects.  But that appears not to be a simple fix---trying 
out that change causes problems that seem to be related to garbage 
collection or other internals of storage management.  A change for the 
future perhaps ...