[Rd] Creating an S3 method when the generic function is defined in another (imported) package

Arne Henningsen arne.henningsen at googlemail.com
Sun May 16 22:32:35 CEST 2010


On 14 May 2010 10:37, Achim Zeileis <Achim.Zeileis at uibk.ac.at> wrote:
> On Fri, 14 May 2010, Arne Henningsen wrote:
>> In one of my packages (maxLik), I would like to add an S3 method,
>> where the generic function (estfun) is defined in another package
>> (sandwich). Everything works fine if my package "Depends" on the other
>> package and I import the generic function "estfun" from the "sandwich"
>> package and define the new method in the NAMESPACE file. However, I
>> prefer not to load the entire other package just to use a single
>> generic function from it. Therefore, I replaced "Depends" by "Imports"
>> in the DESCRIPTION file and (re-)exported "estfun" in the NAMESPACE
>> file. Now "R CMD check" warns about the undocumented code object
>> "estfun" but I do not want to include a duplicate of the documentation
>> of "estfun". Do you know a better solution?
>
> I probably wouldn't re-export the estfun() generic. People will probably
> load "sandwich" anyway before calling estfun(), in particular if they want
> to compute the sandwich() covariance matrix.

That's certainly the best solution for this issue Thanks!
However, I have basically the same problem in another package, where
the method can be (reasonably) applied without loading the package, in
which the generic function is defined. Hence, requiring that the user
loads the other package "by hand" is no solution here. So is there a
better solution than making my package *depend* on the other package
or including a duplicate of the documentation of the generic function?

Thanks a lot,
/Arne

-- 
Arne Henningsen
http://www.arne-henningsen.name



More information about the R-devel mailing list