[R] Simple methods question

Sean Davis
Thu, 21 Apr 2005 12:38:48 -0000

I would like to create a function with methods with the same behavior
for both numeric and logical arguments (using S4 methods) and different
for matrix.

I would typically do:

setGeneric('foo',function(x) standardGeneric('foo'))
setGeneric('foo','numeric',function(x) {...stuff 1...})
setGeneric('foo','logical',function(x) {...stuff 1...})
setGeneric('foo','matrix',function(x) {....stuff 2...})

If "stuff1" is identical for numeric and logical, can the two
setGenerics be "combined" somehow?

Thanks,
Sean