[Bioc-devel] Tip for Bioc developers: use Collate with S4

Seth Falcon sfalcon at fhcrc.org
Fri Apr 7 23:31:43 CEST 2006


Hello developers,

If your package defines S4 classes or methods, I'd like to encourage
you to add a Collate field to your package's DESCRIPTION file.  Why?
What does the Collate field do?

The Collate field allows you to specify the order in which your .R
files get parsed (see the Writing R Extensions manual for details).
With S4 you generally want the following order:

1. class definitions
2. generic function definitions
3. method definitions
4. everything else

Most of the time, when you get the order wrong, your package simply
won't load.  But there are more subtle issues as well.  Details below
for the curious.

To summarize: if you define S4 classes or methods, specify a Collate
field in the DESCRIPTION file and use the above suggestion for loading
order.

Based on the above, I will profer a suggested organization of .R files
(just a suggestion that I've recently been finding useful):

    AllClasses.R 
        contains all calls to setClass and nothing else.
    
    AllGenerics.R 
        contains all calls to setGeneric and nothing else.
    
    somegeneric-methods.R 
        contains setMethod("somegeneric", ...) calls and helper
        functions.


Best,

+ seth

PS: Here's the sort of subtle issue you can run into if you don't
provide a Collate field:

If you define a method for plot (which is an S3 generic), but your
setMethod comes after code that calls plot(yourObj), then sometimes
you end up getting the default plot method instead of yours.



More information about the Bioc-devel mailing list