Skip to content

[R-pkg-devel] NAMESPACE issue and grDevices

3 messages · Kevin Coombes, Jeff Newmiller, Duncan Murdoch

#
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

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

Best,
 ? Kevin
#
I think yes. If a direct user of graphics opted not to call smoothScatter then they would have no need to even install KernSmooth. However, since generics automatically trigger loading of class-specific methods, one of which in your case includes that dependency, your package cannot avoid at least importing KernSmooth.
On August 24, 2019 7:36:44 AM PDT, Kevin Coombes <kevin.r.coombes at gmail.com> wrote:

  
    
#
On 24/08/2019 10:36 a.m., Kevin Coombes wrote:
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.
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