[Rd] S4 fails to initialize linear hierarchies with intermediate VIRTUAL classes

Martin Morgan mtmorgan at fhcrc.org
Thu Oct 18 15:31:44 CEST 2012

Initialization of this simple hierarchy

   A = setClass("A", representation(x="numeric"))
   setClass("B", contains=c("VIRTUAL", "A"))
   C = setClass("C", contains="B")

fails (neat that setClass returns generators; I hadn't realized that before!)

 > C(A())
Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

because in the default coerce<-,C,A-method

 > selectMethod("coerce<-", c("C", "A"))
Method Definition:

function (from, to = "A", value)
     .value <- as(from, "B", TRUE)
     as(.value, "A") <- value

as(from, "B", TRUE) correctly returns an instance of C.

Also VIRTUAL isn't mentioned on ?Classes or ?setClass and isn't documented on 
class?VIRTUAL, making me wonder whether virtual classes are actually meant to be 
supported as part of S4 (they are used regularly in Bioconductor packages)?

Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

More information about the R-devel mailing list