I am developing a package and want to write two subset methods for objects of a custom class, myclass
, with dispatch on two arguments, first one being the object to subset, of class myclass
, and the second being either logical of character vector, like so:
setMethod(
f = "subset",
signature = c(x = "myclass", subset = "logical"),
definition = function(x, subset){
# function body
}
)
setMethod(
f = "subset",
signature = c(x = "myclass", subset = "character"),
definition = function(x, subset){
# different function body
}
)
However, I cannot do this because the S3 generic dispatches on one argument only. And I don't want to create a new generic for subset
because it would mask the existing generic when my package is loaded.
One way around this issue, I think, would be to create a generic and methods of different name, but this would not be very intuitive for the users, right?
So am I missing/misunderstanding something, and is there any witty way to have multiple dispatch for S3 generics?