Skip to content

[R-pkg-devel] Calls not declared

7 messages · Elias Carvalho, Jeff Newmiller, Duncan Murdoch

#
I am developing my first package and found these errors when checking it.

Any help?


* checking dependencies in R code ... WARNING
'library' or 'require' calls not declared from:
  ?qgraph? ?semPlot? ?sna? ?xlsx?
#
On 11/03/2019 9:53 a.m., Elias Carvalho wrote:
Without seeing your package I might be wrong, but I believe this says 
that you have something like

library(qgraph)

somewhere in your R code, without listing

Depends: qgraph

in your DESCRIPTION file.

HOWEVER, fixing this warning will lead to a different one, because 
that's not the recommended way to do things now.  There are two 
possibilities:

1.  Your package is useless without the dependency.

In this case, you should put

Imports:  qgraph, ...

in the DESCRIPTION file (where ... lists the other packages with the 
same status), and list the functions in those packages in your NAMESPACE 
file, using

importFrom(qgraph, ...)

etc.  (If you use Roxygen, you use comments in the source to get it to 
put this into your NAMESPACE file.)

2.  Your package works without the dependency, but you may want to issue 
errors or warnings if it is missing.

Then you should put

Suggests:  qgraph, ...

in the DESCRIPTION file, and to use a function from it, use something like

if (requireNamespace("qgraph")) {
   qgraph::foo(...)
} else
   warning("qgraph is not available.")

Duncan Murdoch
#
I did not see any mention of the distinction between Depends and Imports in the DESCRIPTION file... which is always a risk when duplicating existing documentation in an email. Imports is preferred because the user does not have to put definitions only needed inside your package into their public search path (easier to make under-the-hood changes to the package implementation), but Depends is better when they cannot make use of your package without those definitions (e.g. you return a ggplot object from one of your functions).

So do keep reading the documentation... email is just a kickstart.
On March 11, 2019 8:19:33 AM PDT, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

  
    
#
On 11/03/2019 11:32 a.m., Jeff Newmiller wrote:
You don't need Depends to be able to handle ggplot2 objects. You'll get 
the methods when the package is loaded, so they'll print fine without 
having ggplot2 on the search list.

There are very few cases nowadays where it makes sense to use Depends.

Duncan Murdoch
#
Ah, so as long as you don't need to call a normal function to make use of the returned object you don't need Depends. But in this example, the user would then need to call library(ggplot2) in order to, say, change an axis title.

A bit more subtle than I thought.
On March 11, 2019 10:07:12 AM PDT, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

  
    
#
On 11/03/2019 2:12 p.m., Jeff Newmiller wrote:
I think the current philosophy is that if a user wants to be able to use 
ggplot2 functions, the user should ask for them, they shouldn't be 
automagically added to the search list.  If a user wants to change the 
axis title and doesn't want to have ggplot2 on their search list, that 
is definitely possible:

ggplot2::qplot(1:10, 1:10) + ggplot2::xlab("new x label")

Duncan Murdoch
#
Thank you all !
I used import and works perfectly.

Em seg, 11 de mar de 2019 ?s 16:18, Duncan Murdoch <murdoch.duncan at gmail.com>
escreveu: