Skip to content

[R-pkg-devel] Imports: vs Suggests:

2 messages · Hugh Parsonage, Dirk Eddelbuettel

#
I write to clarify when a package should be in Imports: vs Suggests:.
Does the absence of warnings following a R CMD check --as-cran
guarantee that packages are placed in the correct field?

For example, consider a package with only one exported function:

isTrue <- function(x) hutils::AND(x, TRUE)

When I run R CMD check on this package with an otherwise valid
DESCRIPTION and NAMESPACE, I get a warning about an undeclared import.
That I understand.

But if I add

Suggests: hutils

to DESCRIPTION then R CMD check passes with no warnings. (hutils is
installed on my machine, so I don't receive a note about a package
being unavailable for checking.) My understanding is that because
isTrue won't run without hutils, the package must include hutils under
Imports (or Depends:) not Suggests: , but the R CMD check result gives
the impression that this decision is at the discretion of the package
author. In 'Writing R Extensions', there is a caveat that packages may
be in Suggests: rather than Imports if they are "loaded in the body of
functions", but I don't understand the distinction.

Furthermore, would it make a difference if instead of hutils being
used it was a base package (like stats) or a recommended package (like
KernSmooth)?


Hugh Parsonage
Grattan Institute
#
Hugh,

You may be looking at this from the wrong angle. "Imports" is really an
updated variant of "Depends".  Both of them declaure _unconditional_ use of
another package.  (How they are used is the fine distinction between loading
and attaching which we'll skip here). The key point is that a package named
by either of these _must_ be present.

"Suggests" is different as it declares _optional_ use for which you should
then test.  To take a simple example, Rcpp offers Rcpp.package.skeleton() by
extending / wrapping around package.skeleton().  If and when the _optional_
package pkgKitten (which is a Suggests: of Rcpp) is present, we use it:


    havePkgKitten <- requireNamespace("pkgKitten", quietly=TRUE)

    # ... stuff omitted

    ## update the package description help page
    if (havePkgKitten) {                # if pkgKitten is available, use it
        pkgKitten::playWithPerPackageHelpPage(name, path, maintainer, email)
    } else {
        ### other fallback code ....
    }

See https://github.com/RcppCore/Rcpp/blob/master/R/Rcpp.package.skeleton.R

Hth,  Dirk