From mtmorgan at fhcrc.org  Thu Oct 18 15:31:44 2012
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Thu, 18 Oct 2012 06:31:44 -0700
Subject: [Rd] S4 fails to initialize linear hierarchies with intermediate
 VIRTUAL classes
Message-ID: <508004C0.3010208@fhcrc.org>

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)?

Martin
-- 
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



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