[Rd] setIs and method dispatch in S4 classes

Vincent Carey 525-2265 stvjc at channing.harvard.edu
Fri Apr 7 14:14:07 CEST 2006

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)


getMethods("+")  under both approaches

More information about the R-devel mailing list