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

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jun 4 14:01:56 CEST 2009


The zoo package has lattice methods and does not use require
and it puts lattice in Imports in the DESCRIPTION file.  If a user
wants to the use the zoo lattice functions then they must issue
a library(lattice) call.  As a result users do not have to load
lattice but if they want to use it they must do it themselves.

library(zoo)
z <- zoo(1:4)
xyplot(z) # wrong

library(lattice)
xyplot(z) # yes!

On Tue, Jun 2, 2009 at 5:14 PM, Jeffrey J. Hallman <jhallman at frb.gov> 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.
>
> 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?
>
> --
> Jeff
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list