[Rd] Overloading methods in R

Henrik Bengtsson hb at maths.lth.se
Thu Apr 21 21:32:49 CEST 2005


> -----Original Message-----
> From: r-devel-bounces at stat.math.ethz.ch 
> [mailto:r-devel-bounces at stat.math.ethz.ch] On Behalf Of Jeff Gentry
> Sent: Thursday, April 21, 2005 9:22 PM
> To: Ali -
> Cc: r-devel at stat.math.ethz.ch
> Subject: RE: [Rd] Overloading methods in R
> 
> 
> 
> On Thu, 21 Apr 2005, Ali - wrote:
> > I guess the context says you cannot have something like this in S4:
> > >setGeneric("testFun", function(...)
> > + standardGeneric("testFun"))
> 
> But what is wrong with:
> 
> setGeneric("testFun", function(object, ...))

Naming conflicts, may be the problem. You have that generic in your package,
but I might, without know about yours, and I write 

 setGeneric("testFun", function(x, ...))

in my package, and then a third person that we don't know of, is loading
both of our packages. Ouch! Indeed, this do happens. 

I would be ok with the above, if everyone agreed to use 'object' as the
first argument - but then you have plot(x, ...) and so on. Also, how should
you treat default functions not taking any arguments, e.g. traceback()?
Until then I stick with testFun <- function(...) UseMethod("foo") whenever
possible.

Cheers

Henrik
 
> Keeping in mind that 'object' is the actual instantiated 
> object of the class which you wish to operate on.  I guess I 
> don't see how that aspect is a problem?
> 
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 
>



More information about the R-devel mailing list