r-lib / rcmdcheck

Run R CMD check from R and collect the results
https://rcmdcheck.r-lib.org
Other
115 stars 27 forks source link

Can't found use of libraries on custom expressions #207

Closed latot closed 1 year ago

latot commented 1 year ago

Hi all, I was creating a library with some "types", is a type of expression from the typed library, basically it helps to check if a variable has some propoerties, like the vector to be only integers, a dataframe with some columns, etc, etc.

The code works like this:

sfnetworks_sfnetwork <- typed::as_assertion_factory(function(
    value,
    null_ok = FALSE) {
  if (null_ok && is.null(value)) {
    return(NULL)
  }
  if (!sfnetworks::is.sfnetwork(value)) {
    e <- sprintf(
      "%s\n%s",
      "type mismatch",
      waldo::compare(
        typeof(value),
        "sfnetworks",
        x_arg = "typeof(value)",
        y_arg = "expected"
      )
    )
    stop(e, call. = FALSE)
  }

  value
})

In the package sfnetworks is added as a needed package, but rcmdcheck says:

rcmdcheck::rcmdcheck()
── R CMD build ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file ‘.../DESCRIPTION’ ...
─  preparing ‘geotypes’:
✔  checking DESCRIPTION meta-information ...
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘geotypes_0.0.1.tar.gz’

── R CMD check ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─  using log directory ‘/tmp/Rtmp6pcvWP/file36fc25c70fe02/geotypes.Rcheck’
─  using R version 4.3.1 (2023-06-16)
─  using platform: x86_64-pc-linux-gnu (64-bit)
─  R was compiled by
       x86_64-pc-linux-gnu-gcc (Gentoo Hardened 12.3.1_p20230526 p2) 12.3.1 20230526
       GNU Fortran (Gentoo Hardened 12.3.1_p20230526 p2) 12.3.1 20230526
─  running under: Gentoo Linux
─  using session charset: UTF-8
✔  checking for file ‘geotypes/DESCRIPTION’ ...
─  this is package ‘geotypes’ version ‘0.0.1’
─  package encoding: UTF-8
✔  checking package namespace information ...
✔  checking package dependencies (15.2s)
✔  checking if this is a source package ...
✔  checking if there is a namespace
✔  checking for executable files ...
✔  checking for hidden files and directories ...
✔  checking for portable file names
✔  checking for sufficient/correct file permissions
✔  checking whether package ‘geotypes’ can be installed (1000ms)
✔  checking installed package size ...
✔  checking package directory
✔  checking DESCRIPTION meta-information ...
✔  checking top-level files ...
✔  checking for left-over files
✔  checking index information
✔  checking package subdirectories ...
✔  checking R files for non-ASCII characters ...
✔  checking R files for syntax errors ...
✔  checking whether the package can be loaded ...
✔  checking whether the package can be loaded with stated dependencies ...
✔  checking whether the package can be unloaded cleanly ...
✔  checking whether the namespace can be loaded with stated dependencies ...
✔  checking whether the namespace can be unloaded cleanly ...
✔  checking loading without being on the library search path ...
N  checking dependencies in R code (367ms)
   Namespaces in Imports field not imported from:
     ‘sf’ ‘sfnetworks’
     All declared Imports should be used.
✔  checking S3 generic/method consistency ...
✔  checking replacement functions ...
✔  checking foreign function calls ...
✔  checking R code for possible problems (767ms)
✔  checking Rd files ...
✔  checking Rd metadata ...
✔  checking Rd cross-references ...
✔  checking for missing documentation entries ...
✔  checking for code/documentation mismatches (539ms)
✔  checking Rd \usage sections (340ms)
✔  checking Rd contents ...
✔  checking for unstated dependencies in examples ...
─  checking examples ... NONE
✔  checking for unstated dependencies in ‘tests’ ...
─  checking tests ...
✔  Running ‘testthat.R’ (666ms)
✔  checking PDF version of manual (1.6s)

   See
     ‘/tmp/Rtmp6pcvWP/file36fc25c70fe02/geotypes.Rcheck/00check.log’
   for details.

── R CMD check results ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── geotypes 0.0.1 ────
Duration: 23.7s

❯ checking dependencies in R code ... NOTE
  Namespaces in Imports field not imported from:
    ‘sf’ ‘sfnetworks’
    All declared Imports should be used.

0 errors ✔ | 0 warnings ✔ | 1 note ✖

Seems if some libraries are used inside some expressions rcmdcheck does not detect it.

There is a sf warning too, because there is other function in my lib the uses it.

Thx!

gaborcsardi commented 1 year ago

What do you get with R CMD check?

jennybc commented 1 year ago

(I was already writing this when @gaborcsardi posted.)

There are some syntactical irregularities above.

But let's assume that's a matter of issue authoring?

There are two main things to know:

  1. The rcmdcheck package runs R CMD check under the hood. So it's transmitting the results of checks maintained in base R, not in this package. If you build and check your package without using rcmdcheck, you'll see the same result.
  2. There are definitely cases where a package uses another package, but R CMD check can't detect it. That is addressed here in the R Packages book: https://r-pkgs.org/dependencies-in-practice.html#how-to-not-use-a-package-in-imports
latot commented 1 year ago

mmm, I know the syntax is the best, that is the smaller version, first, I'll update the main post with other code that is easier to check with the full logs.

Now, the libs are not used indirectly, they are in the code, now you can see it.

I didn't know rcmdcheck only capture the results, which is the best place to report this?

Thx!

jennybc commented 1 year ago

which is the best place to report this?

You'd have to report as a bug in base R or open a discussion on a mailing list. But if I were you, I'd use the technique described in the reference above to silence the NOTE and just let it go.

latot commented 1 year ago

D: Okis, thx for the suggestion, if is not worth report it, I'll go with that options :)

Thx!