Adding a method to a generic in another package

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a method to a generic in another package

Jeffrey J. Hallman-2
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Adding a method to a generic in another package

Uwe Ligges-3


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?
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Adding a method to a generic in another package

Gabor Grothendieck
In reply to this post by Jeffrey J. Hallman-2
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 <[hidden email]> 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
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.