Skip to content
Prev 12658 / 63461 Next

Failure to preserve package attribute when coercing S4 objects (PR#6904)

If a class is derived from a superclass using 'contains', then coercion of
an object from the class to the superclass fails to preserve the 'package'
attribute of class of the object.
This occurs only when the derived class has no additional slots.
This is a problem because the 'new' function relies on the exact identity
of the class, including the package attribute.  

This can clearly be worked around by the introduction of dummy slots, but it
took me some time to track down.
[1] "baseClass"
[1] "fancyClass"
setClass("fancyClassExtraSlots",representation(b="numeric"),contains="baseCl
ass")
[1] "fancyClassExtraSlots"
[1] "baseClass" "baseClass" "baseClass"
package attribute
[[1]]
[1] ".GlobalEnv"

[[2]]
NULL

[[3]]
[1] ".GlobalEnv"
An object of class "baseClass"
Slot "a":
[1] 1
Error in initialize(value, ...) : Initialize method returned an object of
class "baseClass" instead of the required class "baseClass"
An object of class "baseClass"
Slot "a":
[1] 2


platform i386-pc-mingw32
arch     i386           
os       mingw32        
system   i386, mingw32  
status                  
major    1              
minor    9.0            
year     2004           
month    04             
day      12             
language R

Jonathan Swinton, Statistical Scientist, Computational Biology, Pathway
Analysis, Global Sciences and Information,  x29400, 19F44 Mereside Alderley
Park.