Skip to content

setIs and method dispatch in S4 classes

1 message · Vincent Carey

#
as a fan of S4 i had a look at this; more definitive
replies are undoubtedly to come
the direct specification of containment in the next statement
is important for the dispatch process
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