[R-pkg-devel] Calls not declared

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Mon Mar 11 18:07:12 CET 2019


On 11/03/2019 11:32 a.m., Jeff Newmiller wrote:
> 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).
> 

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

> So do keep reading the documentation... email is just a kickstart.
> 
> On March 11, 2019 8:19:33 AM PDT, Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
>> On 11/03/2019 9:53 a.m., Elias Carvalho wrote:
>>> 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’
>>
>> 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
>>
>> ______________________________________________
>> 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