[R-pkg-devel] import 'as' from another package

Sebastian Meyer @eb@meyer @end|ng |rom |@u@de
Wed Jul 22 23:12:36 CEST 2020


Following WRE 1.5.6 (Namespaces with S4 classes and methods), you should
have "Depends: methods" in your DESCRIPTION, and "import(methods)" or a
more selective "importFrom(methods, ...)" directive in your NAMESPACE.

Then you would usually use the NAMESPACE directive

    importMethodsFrom(package, generic)

to explicitly import S4 methods exported from another package.
However, the raster package does not do

    exportMethods(coerce)

so if you try

    importMethodsFrom(raster, coerce)

you will get

> Error: object ‘coerce’ is not exported by 'namespace:raster'

when trying to install your package (also during R CMD check, of course).

To solve this problem, you could either

- import raster's entire NAMESPACE via import(raster)

- or ask maintainer("raster") to exportMethods(coerce)

- or do

    importClassesFrom(raster, RasterLayer)

which will magically make the corresponding coerce methods available as
well.

HTH!

	Sebastian Meyer


Am 21.07.20 um 00:41 schrieb Tim Keitt:
> Thanks for pointing to the bug.
> 
> Now I am finding I cannot use the 'as' definitions from 'raster' without
> loading the package. Do I need an @import directive that specifies the
> definitions in the 'raster' package? My understanding is that the
> 'setAs' function generates a 'coerce,...' signature but I'm not sure how
> to import it to my package.
> 
> Thanks again.
> 
> THK
> 
> On Mon, Jul 20, 2020 at 2:25 PM Sebastian Meyer <seb.meyer using fau.de
> <mailto:seb.meyer using fau.de>> wrote:
> 
>     Yes, indeed, it is confusing. You don't need to file a new bug
>     report, though. There is one already:
> 
>     https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17179
> 
>     Please feel free to comment there. This thread could serve as
>     another confirmation. :-)
> 
>     Best regards,
>     Sebastian
> 
>     Am 20. Juli 2020 18:36:21 MESZ schrieb Ben Bolker <bbolker using gmail.com
>     <mailto:bbolker using gmail.com>>:
>     >    I think this is a classic confusing R message.  Try adding methods
>     >to the Imports: statement in your DESCRIPTION file and see if that
>     >helps. (Maybe I should file a bug report about that error message - it
>     >confuses me every time.)
>     >
>     >On 7/20/20 12:34 PM, Tim Keitt wrote:
>     >> It works but "check" gives
>     >>
>     >> > checking package dependencies ... ERROR
>     >>   Namespace dependency not required: ‘methods’
>     >>
>     >> THK
>     >>
>     >> On Mon, Jul 20, 2020 at 11:24 AM Ben Bolker <bbolker using gmail.com
>     <mailto:bbolker using gmail.com>
>     >> <mailto:bbolker using gmail.com <mailto:bbolker using gmail.com>>> wrote:
>     >>
>     >>     @importFrom methods as
>     >>
>     >>     ?
>     >>
>     >>     On 7/20/20 12:06 PM, Tim Keitt wrote:
>     >>     > I have
>     >>     >
>     >>     >    if (!inherits(x, "RasterLayer")) x <- as(x, "RasterLayer")
>     >>     >
>     >>     > in a package and its not finding the coerce definition from the
>     >>     raster
>     >>     > package. I know I need to add an @import roxygen2 directive of
>     >>     some kind,
>     >>     > but I'm not sure the correct syntax. My first try generated a
>     >>     warning that
>     >>     > it was not needed.
>     >>     >
>     >>     > What is the correct way to do this? Or does raster need to
>     >>     export this
>     >>     > definition?
>     >>     >
>     >>     > THK
>     >>     >
>     >>     >       [[alternative HTML version deleted]]
>     >>     >
>     >>     > ______________________________________________
>     >>     > R-package-devel using r-project.org
>     <mailto:R-package-devel using r-project.org>
>     >>     <mailto:R-package-devel using r-project.org
>     <mailto:R-package-devel using r-project.org>> mailing list
>     >>     > https://stat.ethz.ch/mailman/listinfo/r-package-devel
>     >>
>     >>     ______________________________________________
>     >>     R-package-devel using r-project.org
>     <mailto:R-package-devel using r-project.org>
>     >>     <mailto:R-package-devel using r-project.org
>     <mailto:R-package-devel using r-project.org>> mailing list
>     >>     https://stat.ethz.ch/mailman/listinfo/r-package-devel
>     >>
>     >
>     >       [[alternative HTML version deleted]]
>     >
>     >______________________________________________
>     >R-package-devel using r-project.org
>     <mailto:R-package-devel using r-project.org> mailing list
>     >https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list