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

Fails to detect used libraries on code #218

Closed latot closed 11 months ago

latot commented 11 months ago

Hi all, I have uploaded a sample, when we run rcmdcheck::rcmdcheck we can found this message:

N  checking dependencies in R code ...
   Namespace in Imports field not imported from: ‘geotypes’
     All declared Imports should be used.

So, what is the point, is that geotypes is being used on the library, also if you try replace geotypes with a function from for example typed library there is no errors.

No idea why this happens.

bug_typed.zip

geotypes lib: https://github.com/CIT-UAI/geotypes

Thx!

gaborcsardi commented 11 months ago

It is very unlikely that this is an issue with rcmdcheck. Most likely you are not importing anything from the geotypes package, even though you put it in Imports in DESCRIPTION.

gaborcsardi commented 11 months ago

I see that same issue with R CMD check, so this is not an issue with rcmdcheck. I suspect that thanks to typed, R CMD check is unable to see that you are actually using the geotypes package:

cassert <- typed::as_assertion_factory(function(
  value
) {

  ret <- geotypes::Data.frame()
  value

})
print(cassert, useSource = FALSE)
...
    header <- call("{", quote(f <- function (value)
    {
        ret <- geotypes::Data.frame()
        value
    }), substitute(value <- F_CALL, list(F_CALL = f_call)))
...

typed::as_assertion_factory() creates a function object in which the original function is embedded into quote(), which R CMD check does not consider as package code.

This seems like a general issue with the typed package. A workaround is to refer to that package elsewhere, e.g. put a dummy function like this into the package:

dummy <- function() {
  geotypes::Data.frame
}