[R-pkg-devel] NAMESPACE issue and grDevices

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Sun Aug 25 00:45:00 CEST 2019


On 24/08/2019 10:36 a.m., Kevin Coombes wrote:
> Hi,
> 
> I've been building a package and hit a NAMESPACE issue that took a while
> to resolve.
> 
> My package implements a (new) generic function, and the method for a
> package in the class calls the "smoothScatter" function from the
> "graphics" package. I could build and install the package successfully,
> and when I used the generic function, it worked just fine.
> 
> However, when I ran "R CMD check --as-cran", it threw an error from both
> the examples in man pages and a test script. Specifically, the error was
> "package KernSmooth not available". I eventually worked around this
> problem by changing the DESCRIPTION file to "IMPORT KernSmooth" (even
> though I didn't have to actually import anything in "NAMESPACE").
> 
> The underlying issue appears to be that
>       graphics::smoothScatter
> calls a non-exported function from "grDevices"
>        grDevices:::.smoothScatterCalcDensity
> which in turn calls an explicitly qualified function from "KernSmooth"
>       KernSmooth::bkde2D

That looks like a bug in grDevices.  If it suggests KernSmooth, it 
should explicitly check whether it is installed before calling a 
function from it.

> 
> To complicate matters
>       graphics IMPORTs grDevices
> but
>       grDevices only SUGGESTs KernSmooth.
> 
> Since my package already IMPORTed the graphics package and had
>       importFrom("graphics", "smoothScatter")
> in the NAMESPACE, I was surprised that I had to track back through the
> code to find this dependency and had to make it explicitly known within
> the interface to my package.
> 
> Is there something else my package should do? Or should "grDevices"
> actually IMPORT "KernSmooth"?

It could import it, or it could put in a check and a workaround if it is 
not found.

Now that you know about this bug, you could work around it by suggesting 
KernSmooth, and not calling graphics::smoothScatter unless KernSmooth is 
available.

Duncan Murdoch
> 
> Best,
>     Kevin
> 
> ______________________________________________
> 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