Skip to content
Prev 12070 / 12125 Next

[R-pkg-devel] R CMD check false positive unused imports inside R6 class

Hi all,

R CMD check gives a false positive locally when the only usage of an
imported package is through pkg::foo() inside an R6 class. This GitHub repo
contains a full MWE, with log files and a more elaborate explanation:
https://github.com/BjarkeHautop/RCMDcheckFalsePositive

The R package contains a single .R file with this (I'm aware you don't have
to import base packages explicitly, but this is an MWE with only base
packages (except R6)):

filter <- function() {
  message("This is a custom filter function.")
}

DataProcessor <- R6::R6Class(
  "DataProcessor",
  public = list(
    data = NULL,
    initialize = function(data) self$data <- data,

    filter_data = function(data) {
      filter()
      self$data <- stats::filter(self$data, rep(1, 3))
    }
  )
)

When running R CMD check, it will generate the following NOTE:

* checking dependencies in R code ... NOTE
Namespaces in Imports field not imported from:
  ?R6? ?stats?

Interestingly, the NOTE disappears on CRAN release/dev winbuilder.

My questions are:

1. Is this the intended behavior of R CMD check, or is it a bug that it
fails to detect usage of packages inside
R6 classes? If intended (e.g., due to it being too expensive to check for
:: in "hidden places") should this be
mentioned somewhere on WRE? Currently
[WRE](
https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Package-Dependencies-1)
says:
*"The ?Imports? field should not contain packages which are not imported
from (via the NAMESPACE file or :: or ::: operators)"*
indicating that `::` usage should be fully supported.

2. How/Why does the NOTE disappear when checking on CRAN dev winbuilder?
Can I replicate this behavior locally using R CMD check? Will it pass on
CRAN?

Best regards,
Bjarke