[R] Simple methods question

Sean Davis sdavis2 at mail.nih.gov
Thu Apr 21 14:38:48 CEST 2005


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




More information about the R-help mailing list