[R-pkg-devel] Package used unconditionally only in testing

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Fri Jan 8 17:15:20 CET 2021


On 08/01/2021 9:17 a.m., Greg Freedman Ellis wrote:
> Hi all,
> 
> I'm trying to update a package to conform to pass tests given
> `_R_CHECK_DEPENDS_ONLY_=TRUE`.
> 
> In this package, we only use the package `httptest` during testing, but the
> tests are (almost) meaningless if it is not installed, so I would like to
> indicate that it is a required package rather than skipping tests if it is
> not installed.

This sounds wrong.  I don't know the httptest package, but I assume that 
since you were only using it for testing, I might be interested in using 
your package even if I wasn't interested in installing httptest.  Making 
it a hard requirement would force me to install httptest.

> 
> If I move `httptest` to Depends, then I get the error CRAN check note:
>> Namespace in Imports field not imported from: ‘httptest’
>>    All declared Imports should be used.

You *definitely* shouldn't include it in Depends:  that would force it 
onto the search list, and potentially break other things that I'm 
running, e.g. if they have name conflicts with it.

You *probably* shouldn't include it in Imports.  Why force me to load 
another package if I'll never use it?  There's a tiny chance that would 
push my memory use over the edge, and my own code would fail.

It should almost certainly be included in Suggests, and nowhere else.
If that means your tests are skipped, you should feel free to warn the 
user in your test messages:  but it shouldn't cause your tests to fail.

> I think this would best be solved by a DESCRIPTION field that indicates a
> package is required, but only for tests, but I do not see such a field. The
> only solution I can think of is to have a trivial import of `httptest` in
> the main package to silence the NOTE. Is there a better solution?

Most users aren't going to run your tests, so they shouldn't be forced 
to install software that would let them do so.

Duncan Murdoch



More information about the R-package-devel mailing list