Skip to content
Prev 45845 / 63424 Next

Namespace/inheritance problem in S4 methods for a union class

No need for generic functions and methods.  Just looking at the 
hierarchy of the classes shows the problem.

With Martin's simplified version:

 > library(PkgA)
 > extends("A")
[1] "A"
 > library(PkgB)
 > extends("B")
[1] "B" "A"
 > setClassUnion("C", c("matrix", "A"))
 > extends("A")
[1] "A" "C"
 > extends("B")
[1] "B" "A"


So defining the union does not make all the subclasses of "A" members of 
the union.

The next comments are guesses but plausible.  Loading the namespace of 
PkgB may not update the known subclasses of classes from PkgA.

This is one of R's touchier points in general:  The state of things with 
respect to classes and methods changes dynamically as packages are 
loaded.  Until PkgB is loaded, "A" has no known subclasses.

If the guess is correct, then when the  class union is formed, nothing 
tells us that "A" has a subclass "B" that should be added to the union.

Fixing this properly may involve the load-time actions and not be quite 
trivial.

John
On 5/7/13 11:05 PM, Renaud Gaujoux wrote: