[Rd] S4 method implementation for S3 class

Iñaki Úcar
Fri, 22 Sep 2017 12:44:48 -0000

Hi all,

I'm trying to implement the matrix multiplication operator, which is
S4 generic, for an old-style S3 class. The following works as
expected:

x <- 1:10
class(x) <- "myClass"

setOldClass("myClass")
setGeneric("myMethod", function(x, y)
standardGeneric("myMethod"))
setMethod("myMethod", c("myClass", "myClass"),
function(x, y)
message("dispatched!"))

myMethod(x, x)
#> dispatched!

but I don't understand why the following won't:

setMethod("%*%", c("myClass", "myClass"),
function(x, y) message("dispatched!"))

x %*% x
#>      [,1]
#> [1,]  385

Is this approach wrong?

Regards,
I?aki