1

The DESCRIPTION file in R packages has several ways of specifying dependencies, e.g. Depends, Suggests and Imports. Which one should I use to specify a dependency that is optional once the package is installed, but required for running R CMD check?

In my particular case I am using testthat to run some tests automatically when R CMD check is run, but during "normal" operation, testthat is not required. The answer to this question suggests that testthat should be in Suggests, but is that enough to ensure that R CMD check runs correctly?

What I would like to see, if it exists, is a field where I can speciy dependencies that are required only to run R CMD check, which should fail with an appropriate error message if these packages are not available.

Community
  • 1
  • 1
Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204
  • 1
    What you describe is what the `Suggests` field is for (required to check, but not to install the package). In a comment to my answer you said that (someone) told you to remove an example that used a "Suggested" package because `R CMD check` failed. Please provide the error given by `R CMD check`, the example that failed (and the error message). – Joshua Ulrich Apr 02 '13 at 20:00
  • Ok, in this particular case it failed because the dependency required some external software -- so unrelated to the specified dependencies. – Lars Kotthoff Apr 02 '13 at 20:07
  • Maybe this helps: https://github.com/hadley/devtools/wiki/Testing#r-cmd-check – GSee Apr 02 '13 at 22:58

1 Answers1

5

Yes, you should put them in the Suggests field. The only other thing required for R CMD check to run successfully is to ensure the packages in the Suggests field are installed in a location that will be found by R CMD check.

If they're not available, you can set the environment variable _R_CHECK_FORCE_SUGGESTS=false and R CMD check will run, with a "NOTE" about the missing suggested packages.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
  • Ok, but how can I make sure that it works for anybody running `R CMD check`? My concern is not about making it work for me, but for anybody regardless of whether they have `testthat` installed or not and without requiring them to set environment variables. – Lars Kotthoff Apr 02 '13 at 18:59
  • @LarsKotthoff: I don't understand. You say that you want `testthat` to be _required_ for running `R CMD check`, but you also want `R CMD check` to work if `testthat` isn't available? – Joshua Ulrich Apr 02 '13 at 19:06
  • I don't want to require it, but running `R CMD check` needs it to succeed. My concern is that the check will fail when `testthat` is not available even though there isn't a real problem. – Lars Kotthoff Apr 02 '13 at 19:19
  • 1
    It still seems like you want something that is mutually exclusive. If you want your checks to run automatically with `R CMD check`, `testthat` must be installed. If you don't want to require that `testthat` be installed, then you can't run your checks automatically with `R CMD check`. – Joshua Ulrich Apr 02 '13 at 19:23
  • Yes, that's exactly my problem. That's why I was wondering whether there is anything like a `Check-depends` field where such dependencies can be given. – Lars Kotthoff Apr 02 '13 at 19:27
  • @LarsKotthoff, if testthat is in Suggests, then the user will have to have it installed in order to run R CMD check without using environment variables, and the user will not have to have testthat installed in order to install or load the package. AFAICT, that's exactly what you asked for, no? – GSee Apr 02 '13 at 19:37
  • I was told when uploading a package that had a dependency specified in `Suggests` to remove the example that used it as `R CMD check` failed. That is, putting it in `Suggests` is *not* enough to make sure that it is required when checking the package. Is there any way to do this? – Lars Kotthoff Apr 02 '13 at 19:43
  • 1
    @LarsKotthoff: please update your question with more complete information. Why did `R CMD check` fail? What was the code in the example? Did the example ensure the package was loaded? I.e. please give us the actual problem, not a description of what you think the problem is. – Joshua Ulrich Apr 02 '13 at 19:46
  • I've done that, but I guess that the answer is "no". I'll accept your answer as a good explanation of how `Suggests` (the next best thing) works. – Lars Kotthoff Apr 02 '13 at 19:55
  • 2
    You did what? You haven't provided any code, error message(s), etc. All we have is a description of what you think the problem is, and what you think the solution should be. – Joshua Ulrich Apr 02 '13 at 20:02
  • 1
    @LarsKotthoff Why not wrap the tests in `if(require(testthat)) { .... }`? `Suggests` don't have to be available so you should not make the package checking depend on them. If you have **testthat** installed you get the extra checks (or all checks) when you do `R CMD check`, if you don't have it etc the package still checks OK. – Gavin Simpson Apr 02 '13 at 21:25