Skip to content
Prev 15877 / 63461 Next

Overloading methods in R

On Thu, 21 Apr 2005, Ali - wrote:
I might be misunderstanding what you're getting at here, but if indeed I
do understand this correctly then not only is it still possible in S4 but
I was tought that it was generally considered Good Behavior.

Consider the following code snippet:
[1] "foo"
[1] "bar"
+ standardGeneric("testFun"))
[1] "testFun"
+ print(x))
[1] "testFun"
+ print(a+b+c))
[1] "testFun"
[1] "blah"
[1] 6

Here I've defined a generic 'testFun' and assigned it the '...' argument
(note that you could still specify required arguments,
e.g. 'function(object, anArg, anotherArg, ...)' in the segGeneric
command).  Then when I use setMethod(s) for the two classes I am able to
specify differing sets of arguments for each class.