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? Thanks a lot! Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Universit? degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 (0 40) 5 58-34 47 email: cbeleites at units.it
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
Dear Duncan and Oleg, thanks for your answers. For the moment, I'll use functions. Happy new year, Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Universit? degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 (0 40) 5 58-34 47 email: cbeleites at units.it