[R] Adding a method to a generic in another package

Uwe Ligges ligges at statistik.tu-dortmund.de
Thu Jun 4 13:24:45 CEST 2009



Jeffrey J. Hallman wrote:
> I am the maintainer of the 'tis' package.  One of the functions in my package
> is 'nberShade'.  A user wants to make nberShade generic, with the old version
> renamed as nberShade.default, all of which is fine with me.  And he wants to
> add a new method, nberShade.ggplot, which works for objects of class ggplot.
> He also wants to add a method fortify.tis for the generic fortify defined in
> ggplot2. 
> 
> The nberShade.ggplot method uses a bunch of other functions from the ggplot2
> package, and it's first line is
> 
> require("ggplot2")
> 
>>From what he tells me, this function works.  
> 
> Where I'm having trouble is figuring out what I have to do to get the tis
> package to pass R CMD check.  I really don't want to force users of the tis
> package to have to install ggplot2.  What can I do?  Is it enough to have 
 >
> Imports: ggplot2
> 
> in the DESCRIPTION file and 
> 
> import(ggplot2)
> 
> in the NAMESPACE file?  I've done that, but I still get this warning from R
> CMD check:
> * checking for unstated dependencies in R code ... WARNING
> 'library' or 'require' calls not declared from:
>   ggplot2
> See the information on DESCRIPTION files in the chapter 'Creating R
> packages' of the 'Writing R Extensions' manual.

If you load another package explicitly, it is not sufficient to declare 
it as imports (because you are not only importing from it), but you need 
it in Depends, Suggests or Enhances, dependending on the tasks you are 
going to perform. Since you do not want that the user needs to install 
it, you want to write it into Suggests, I think.

  Uwe Ligges



> Well, I did read the manual, and it seems to say that what I'm doing is OK. So
> why am I getting the warning?
>




More information about the R-help mailing list