[R] Understanding S4 method dispatch
Hadley Wickham
h.wickham at gmail.com
Wed Aug 14 17:25:10 CEST 2013
> In my opinion the reason for the behavior lies in the specific multiple inheritance structure between AB, B and A.
So what if we don't make such a weird inheritance structure, and
instead have A and B inherit from a common parent:
setClass("A", contains = "list")
setClass("B", contains = "list")
setClass("AB", contains = c("A", "B"))
setGeneric("f", function(x, y) standardGeneric("f"))
setMethod("f", signature("A", "A"), function(x, y) "A-A")
setMethod("f", signature("B", "B"), function(x, y) "B-B")
ab <- new("AB")
f(ab, ab)
Why isn't there a warning about ambiguous dispatch?
Hadley
--
Chief Scientist, RStudio
http://had.co.nz/
More information about the R-help
mailing list