R CMD check methods

I am using methods::is() in a package. R CMD check does not seem to agree with it.

If I use is :

  no visible global function definition for ‘is’
  Consider adding
    importFrom("methods", "is")
  to your NAMESPACE file (and ensure that your DESCRIPTION Imports field
  contains 'methods').

If I include @importFrom methods is as suggested:

> checking package dependencies ... ERROR
  Namespace dependency not required: ‘methods’
  
  See section ‘The DESCRIPTION file’ in the ‘Writing R Extensions’
  manual.

I also tried methods::is :

W  checking dependencies in R code (2.6s)
   '::' or ':::' import not declared from: ‘methods’

My DESCRIPTION and NAMESPACE are generated by Roxygen2, so I assume it is properly generated.

Just using is() seems to be the best option, but is there a way to resolve the complaints?

I think this means you need to add the package in the DESCRIPTION, in the Import field.
roxygen2 will take care of the NAMESPACE if you had @importFrom but you still need to add to description.

The check process will verified if packages used (though ::, ::: or NAMESPACE) are indeed declared in DESCRIPTION

Do you already have Imports: methods in your DESCRIPTION ?

1 Like

I tried adding methods in DESCRIPTION manually at one point, but that did not solve the issue.

Since I posted the initial message, what ended up working is instead of @importFrom methods is, just using @import methods. I am happy it worked, but it still does not make sense to me that only one of those options worked.