From stvjc at channing.harvard.edu  Fri Apr  7 14:14:07 2006
From: stvjc at channing.harvard.edu (Vincent Carey 525-2265)
Date: Fri, 7 Apr 2006 08:14:07 -0400 (EDT)
Subject: [Rd] setIs and method dispatch in S4 classes
Message-ID: <Pine.GSO.4.58.0604070810220.29241@capecod.bwh.harvard.edu>


as a fan of S4 i had a look at this; more definitive
replies are undoubtedly to come

> ## now: B00 mother class to B01 and B02, and again B02 "contains" B01 by setIs:
> setClass("B00", representation(a="numeric"))
> setClass("B01", representation(a="numeric",b="numeric"), contains= "B00")

the direct specification of containment in the next statement
is important for the dispatch process

> setClass("B02", representation(a="numeric",d="numeric"), contains= "B00")

if we omit the containment assertion your expectations are met

setClass("B02", representation(a="numeric",d="numeric"))
setIs("B02","B01",coerce=function(obj){new("B01", a=obj at a, b=obj at d)},
       replace=function(obj,value){new("B01", a=value at a, b=value at b)})

two diagnostic steps that are illuminating are

getClass("B02")  under both approaches (with and without contains="B00"
in definition of B02 class)

and

getMethods("+")  under both approaches



[Rd] setIs and method dispatch in S4 classes
Vincent Carey 525-2265