[Bioc-devel] BiocGenerics / NAMESPACE question

Hervé Pagès hpages at fhcrc.org
Mon Dec 5 21:05:54 CET 2011


On 11-12-05 11:36 AM, Kasper Daniel Hansen wrote:
> 2011/12/5 Hervé Pagès<hpages at fhcrc.org>:
>> Hi Kapser,
>>
>>
>> On 11-12-04 10:40 AM, Kasper Daniel Hansen wrote:
>>>
>>> I have looked a bit at BiocGenerics.  I may not be up to date on the
>>> latest in export/NAMESPACE, but why are (almost) all the generics
>>> exported as
>>>
>>>    export(lapply)
>>>
>>> and not
>>>
>>>    exportMethod(lapply)
>>>
>>> and why is combine/updateObject different.  Is it because you need
>>> export() to register the generic and only exportMethod if the package
>>> defines a method aside from the generic?
>>
>>
>> Yep. export() is for a function (a generic is a function),
>> exportMethod() is for a method. There is no "lapply" method defined
>> in BiocGenerics, just the "lapply" generic function.
>>
>>
>>> And does that mean I need to
>>> treat exporting a method differently depending on whether or not the
>>> package I am writing defines the generic or not?
>>
>>
>> If the package you are writing defines a method for a generic that is
>> defined elsewhere, then you need to import the generic and to export
>> only the method. If your package defines the generic and at least one
>> method for it, then you don't need to import anything (besides the
>> method package of course) and you need to export the generic (with
>> export()) and the method (with exportMethod()).
>
> Thanks a lot, this is a clear explanation and it also makes sense.
>
> However, I suspect that many packages do not follow this.  At least
> Biobase does not, since it only uses exportMethods() without exporting
> the generic separately for all the methods (like sampleNames,
> phenoData etc).

Right. I found this in the "Writing R Extensions" manual:

   Note that exporting methods on a generic in the namespace will also
   export the generic, and exporting a generic in the namespace will
   also export its methods.

I didn't know this. But it sounds more like a "convenience" feature
to me and maybe it's "cleaner design" to not to rely on it?

H.


>
> Kasper


-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the Bioc-devel mailing list