Closed
Description
"14.7.5 Double dispatch" says:
The methods are different, and R calls the first method with a warning.
But the actual implementation seems different; C function DispatchGroup
is
if( lsxp != rsxp ) {
if ( isFunction(lsxp) && isFunction(rsxp) ) {
/* special-case some methods involving difftime */
...snip...
else {
warning(_("Incompatible methods (\"%s\", \"%s\") for \"%s\""),
lname, rname, generic);
UNPROTECT(4);
return 0;
}
}
This means do_arith
skips this if
branch and uses the internal method dispatch, which follows after:
if (DispatchGroup("Ops", call, op, args, env, &ans))
return ans;
So, I feel the line should be
The methods are different, and R uses the internal dispatch with a warning.
(FWIW, I noticed this when I investigated the error below, which I don't come up with the nice way to do (other than using S4) yet...)
library(ggplot2)
set.seed(100)
d1 <- data.frame(x = 1:100, y = cumsum(runif(100)))
d2 <- data.frame(x = 1:100, y = cumsum(runif(100)))
plot_all <- function(...) {
l <- lapply(list(...), function(d) ggplot(d, aes(x, y)) + geom_line())
l <- unname(l)
class(l) <- "manyplot"
l
}
print.manyplot <- function(x, ...) {
do.call(gridExtra::grid.arrange, x)
}
p <- plot_all(d1, d2)
p
`+.manyplot` <- function(e1, e2) {
l <- lapply(e1, function(x) x + e2)
class(l) <- "manyplot"
l
}
p + theme_bw()
#> Warning: Incompatible methods ("+.manyplot", "+.gg") for "+"
#> Error in p + theme_bw(): non-numeric argument to binary operator
Metadata
Metadata
Assignees
Labels
No labels