[R-pkg-devel] check warning in examples

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Tue Apr 30 01:59:39 CEST 2019

On 29/04/2019 6:12 p.m., Berry Boessenkool wrote:
> Hi,
> my package has a warning in check (locally + all rhub::check_for_cran platforms):
> * checking for unstated dependencies in examples ... WARNING
> Warning: parse error in file 'berryFunctions-Ex.R':
> 'match' requires vector arguments
> When I run the -Ex.R file locally (Windows 10, R3.5.2), things work fine, however.
> parse("*-Ex.R") works fine.
> devtools::run_examples() works fine as well.
> https://github.com/brry/berryFunctions
> Does anybody have an idea how to locate the cause for such a warning?
> Does it mean something that this turns up in check unstated deps while checking examples itself has no problems?

It looks like a bug in the QC code, triggered by this line in one of 
your examples for ?dataStr:

   data(list=x$Call, package=x$Package, envir=env)

In the R-devel source file src/library/tools/R/QC.R, in function 
.check_packages_used_helper(), there's a nested function called 
find_bad_exprs().  It parses lots of calls, and in particular, in 
handling calls to data(), it has this code:

if(Call %in%  "data" && length(e) >= 3L) {
                 mc <- match.call(utils::data, e)
                 if(!is.null(pkg <- mc$package) && pkg %notin% 
                     bad_data <<- c(bad_data, pkg)

Here e is the quoted expression from above, and Call is "data".  This 
sets pkg to the quoted expression x$package, and the test "pkg %notin% 
depends_suggests" dies with the error message you saw.

I think the fix for this is to check that pkg works out to be a string, 
not an expression, e.g.

  if(!is.null(pkg <- mc$package) && is.character(pkg) && pkg %notin% 

I'm not sure what would be the best thing for you to do.  You could fool 
the test by using obscure code like this

   do.call("data", list(list = x$Call, package=x$Package, envir=env))

or maybe you could just ignore the warning, pointing out that it is a 
bug in the QC code.

Duncan Murdoch

More information about the R-package-devel mailing list