Skip to content

questions on generic functions

2 messages · Wayne (Yanwei) Zhang, Uwe Ligges

#
Hi all,

I'm trying to build a package, but run into problems with generic functions. 

I have two classes "aa" and "bb", and defined the function "summary.bb". Now I 
want to make "summary.bb" the default method for both classes "aa" and "bb". 
That is, if I have two objects  "object.aa" and "object.bb" from class "aa" and "bb" 
respectively, the function call "summary(object.aa)" and "summary(object.bb)" will 
apply the function "summary.bb" at default.  How can I do that? Should I use 
"setMethod" ?  Thanks a lot. 

Regards,
Wayne
#
Wayne (Yanwei) Zhang wrote:
If you are using S3 approach, you can either define

summary.aa <- summary.bb

or make use of inheritance, i.e. you need to create object of class aa with

class(object.aa) <- c("aa", "bb")
From the naming scheme above I feel you are going the S3 way. If you 
want to use S4 (what setMethod is intended for), you can either use 
setMethod() for the declaration or also use inheritance (already in the 
class definition of class aa in setClass()).

Uwe Ligges