I have an R6 class that I wish to have the %*%
method defined. I have seen in another question how to accomplish this with a new S4 method. However, I have tried this approach and it fails when I try to create the S4 %*%
method for my R6 class. For example:
library(R6)
setOldClass(c("TestR6", "R6"))
TestR6 <- R6Class("TestR6", public = list(.x = "numeric"))
setMethod("%*%", c(x = "TestR6", y = "TestR6"),
function(x, y){
print('the matmult operation')
}
)
x <- TestR6$new()
y <- TestR6$new()
x %*% y
Error in x %*% y : requires numeric/complex matrix/vector arguments
And yet, it still works if I create the foo
method.
setGeneric("foo", signature = "x",
def = function(x) standardGeneric("foo")
)
setMethod("foo", c(x = "R6"),
definition = function(x) {
"I'm the method for `R6`"
})
try(foo(x = TestR6$new()))
[1] "I'm the method for `R6`"
Why doesn't it work for the %*%
method?