[Rd] methods vs. functions
murdoch at stats.uwo.ca
Mon Dec 22 16:11:59 CET 2008
On 12/22/2008 9:40 AM, Claudia Beleites wrote:
> Dear List,
> a second, more general, question concerning S4 classes.
> I have a bunch of functions/methods for my class.
> At the moment I have them as methods, because they work on objects of my S4
> class and therefore "belong" to that class.
> On the other hand, it is comparably unlikely that someone else wants the same
> kind of method.
> And package.skeleton () produces the xzy-methods.Rds. But for the
> documentation I rather need "normal" function definitions. I know that I can
> write the Rd files just as if it was a normal function, but this got me to ask
> myself whether it is a good idea to have methods or whether I should rather
> use "normal" functions?
> If I understood the concept of namespace correctly, a package with a namespace
> avoids trouble with clashing function names - so I don't need to worry about
> that using functions (I anyways have some functions, that should not be
> methods of the class).
> Any comments?
In the S4 scheme, methods "belong" to the generic, not to the class. If
you only have one method for each generic and don't plan for more, it
probably makes more sense to make it a regular function: it will run a
little bit faster, and be noticeably easier to debug.
More information about the R-devel