[R] defining a method for multiple classes

Robert M. Flight rflight79 at gmail.com
Tue Mar 8 21:12:46 CET 2011


Is it possible to define a method for multiple classes (that are not
simply extensions of the other) without making separate setMethod()
calls?

As far as I understand it, this is how to currently set methods for
multiple classes:

setClass("myClass1", representation=representation(x="numeric",y="numeric"))
setClass("myClass2", representation=representation(x="numeric",z="character"))

setGeneric("x", function(object) standardGeneric("x"))

setMethod("x", signature("myClass1"), function(object) object at x)
setMethod("x", signature("myClass2"), function(object) object at x)


I was wondering if it is possible to do the equivalent of:

setMethod("x", signature(c("myClass1","myClass2")), function(object) object at x)

Or am I always required to do two separate setMethods?

Thanks,

-Robert

Robert M. Flight, Ph.D.
University of Louisville Bioinformatics Laboratory
University of Louisville
Louisville, KY

PH 502-852-1809 (HSC)
PH 502-852-0467 (Belknap)
EM robert.flight at louisville.edu
EM rflight79 at gmail.com

Williams and Holland's Law:
       If enough data is collected, anything may be proven by
statistical methods.



More information about the R-help mailing list