From murdoch at stats.uwo.ca  Mon Dec 22 16:11:59 2008
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Mon, 22 Dec 2008 10:11:59 -0500
Subject: [Rd] methods vs. functions
In-Reply-To: <200812221540.12303.cbeleites@units.it>
References: <200812221540.12303.cbeleites@units.it>
Message-ID: <494FAE3F.7090909@stats.uwo.ca>

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.

Duncan Murdoch



[Rd] methods vs. functions
Duncan Murdoch