Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Method dispatch when mixing S3 and S4

$
0
0

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.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>