Associated with this question, but a little different and, I hope, more understandable.
I'm looking for a clean way to officially register methods for classes S4 and S3, but not relying on the awful S3-dot naming scheme to send. Example:
setClass("foo"); setClass("bar"); setGeneric("test", function(x, ...){ standardGeneric("test"); }); setMethod("test", "bar", function(x, ...){ return("success (bar)."); }); obj1 <- 123; class(obj1) <- "bar"; test(obj1);
This example shows how we can register the test method for S3 objects of class bar , without having to call the function test.bar , which is great. However, the limitation is that we register methods in this way, they will be sent only to the first class S3 of the object. For example:
obj2 <- 123; class(obj2) <- c("foo", "bar"); test(obj2);
This does not work, because the S4 method dispatcher will only try the foo class and its superclasses. How can this example be extended to automatically select the test method for bar if no suitable method for foo ? For example. S3, but no need to return to the name of the whole test.foo and test.bar ?
So, in short: how to create a universal function that uses the scheduling of a formal method, but, in addition, drops out of the second, third, etc. object for S3 objects with multiple classes.
Jeroen
source share