[R] Where to declare S4 classes?
sfalcon at fhcrc.org
Sun Mar 5 18:22:21 CET 2006
Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> writes:
> OK. Looks like I have got it... going through the source code of sp,
> classes are declared as usual functions in *.R files.
I'll add in a few suggestions that I have found useful for developing
heavily S4 classes (you don't have to do it this way, your life may
not be better if you do, etc):
* Put all setClass calls in AllClasses.R
* Put all setGeneric calls in AllGenerics.R
* Put setMethod("foo", ...) calls in foo-methods.R
* use a NAMESPACE file
Why do I find this helpful?
With all of the classes in one place it is easy to see what *things*
the package defines, how they are structured, and how they relate to
each other. Similarly, having all the generics in one place provides
a nice overview of the behaviors defined by the package.
Methods separate from the classes makes sense because in S4 methods
don't belong to classes. Since classes and methods are decoupled in
S4, it makes sense to me to organize them that way in the source code.
More information about the R-help