[R-pkg-devel] Why doesn't R CMD check warn that globalVariables() is undefined/not imported?
Henrik Bengtsson
henr|k@bengt@@on @end|ng |rom gm@||@com
Tue Sep 24 20:07:51 CEST 2019
'R CMD check' will give a warning that 'speed' is an unknown variable in:
low_speeds <- function(limit) {
subset(datasets::cars, speed <= limit)
}
We can tell 'R CMD check' that 'speed' is a false positive by
declaring it a "global" variable. This can be done, by:
low_speeds <- function(limit) {
subset(datasets::cars, speed <= limit)
}
utils::globalVariables("speed")
So, far so good. But, why doesn't 'R CMD check' complain about
'globalVariables' not being defined if we use
globalVariables("speed")
without utils::* and without having an importFrom("utils",
"globalVariables") in the NAMESPACE?
For what it's worth, if I add a globalVariables() inside a function
definition, e.g.
low_speeds <- function(limit) {
globalVariables("speed")
subset(datasets::cars, speed <= limit)
}
globalVariables("speed")
then 'R CMD check' will indeed complain about that inner globalVariables():
$ R --vanilla CMD check teeny_0.1.0.tar.gz
* using log directory ‘/home/hb/repositories/teeny.Rcheck’
* using R version 3.6.1 (2019-07-05)
* using platform: x86_64-pc-linux-gnu (64-bit)
[...]
* checking R code for possible problems ... NOTE
low_speeds: no visible global function definition for ‘globalVariables’
Undefined global functions or variables:
globalVariables
Consider adding
importFrom("utils", "globalVariables")
to your NAMESPACE file.
Is this an oversight in R CMD check, or is it implicit that the
'utils' package is attached when installing and checking packages and
we can use 'utils' objects at the top level of a package?
Thanks,
Henrik
More information about the R-package-devel
mailing list