I'd like to understand the steps R goes through to find the appropriate function when mixing S3 and S4. Here's an example:
set.seed(1)
d <- data.frame(a=rep(c('a', 'b'), each=15),
b=rep(c('x', 'y', 'z'), times=5),
y=rnorm(30))
m <- lme4::lmer(y ~ b + (1|a), data=d)
l <- lsmeans::lsmeans(m, 'b')
multcomp::cld(l)
I don't fully understand what happens when the final line gets executed.
multcomp::cld
prints UseMethod("cld")
, so S3 method dispatch.
isS4(l)
shows that l
is an S4 class object.
It seems that, despite calling an S3 generic, the S3 dispatch system is completely ignored. Creating a function print.lsmobj <- function(obj) print('S3')
(since class(l)
is lsmobj
) and running cld(l)
does not print "S3"
.
showMethods(lsmobj)
or showMethods(ref.grid)
(the super class), do not list anything that resembles a cld
function.
Using debugonce(multcomp::cld)
shows that the function that is called eventually is cld.ref.grid
from lsmeans
.
I was wondering, however, how to realise that cld.ref.grid
will eventually be called without any "tricks" like debugonce
. That is, what are the steps R performs to get to cld.ref.grid
.