Combining S4 and S3 methods in a single function
问题 What is a good way of defining a general purpose function which should have implementations for both S3 and S4 classes? I have been using something like this: setGeneric("myfun", function(x, ...){ standardGeneric("myfun"); }); setMethod("myfun", "ANY", function(x, ...) { if(!isS4(x)) { return(UseMethod("myfun")); } stop("No implementation found for class: ", class(x)); }); This succeeds: myfun.bar <- function(x, ...){ return("Object of class bar successfully dispatched."); } object <-