[R-pkg-devel] Handling Not-Always-Needed Dependencies? - Part 2
Duncan Murdoch
murdoch.duncan at gmail.com
Thu Aug 4 19:18:53 CEST 2016
On 04/08/2016 12:55 PM, Bill Denney wrote:
> On 8/4/2016 11:51 AM, Dirk Eddelbuettel wrote:
>> On 4 August 2016 at 11:46, Paul Gilbert wrote:
>> | If my package has a test that needs another package, but that package is
>> | not needed in the /R code of my package, then I indicate it as
>> | "Suggests", not as "Depends" nor as "Imports". If that package is not
>> | available when I run R CMD check, should the test pass?
>>
>> Wrong question.
>>
>> Better question: Should the test be running? My preference is for only
>> inside of a requireNamespace() (or equivalent) block as the package is not
>> guaranteed to be present. In theory.
>>
>> In practice people seem to unconditionally install it anyway, and think that
>> is a good idea. I disagree on both counts but remain in the vocal minority.
> As another package maintainer, I had almost the identical question
> reading the previous (long) thread, but the three answers here don't
> give the same answer. My question I can make even more concrete:
>
> I use the testthat package for my testing. I never use it in the R code
> itself, and it is explicitly only used for testing. Should that be
> included as "Depends" because every test requires it or "Suggests"
> because no end user ever needs it?
>
> If "Depends", then it leads to over-installation of the package by end
> users who don't care about running tests locally. If "Suggests", then
> all of the tests would fail (assuming that Dirk's suggestion is
> implemented).
I'd say you should use Suggests, and test for its presence at the start
of your test scripts, e.g.
if (!require("testthat"))
stop("These tests need testthat")
or
if (!requireNamespace("testthat"))
stop("these tests need testthat")
(The latter means you'd need to prefix all testthat functions with
"testthat::", but it has the advantage that their names don't conflict
with yours.)
Or perhaps you don't want to give an error, you just want to skip some
of your tests. It's your decision.
Duncan Murdoch
More information about the R-package-devel
mailing list