2

Running R CMD check on a package of mine throws a note regarding undefined global functions or variables. Consider the following example:

mypackage: no visible binding for global variable 'a'
mypackage: no visible global function definition for '.'
mypackage: no visible binding for global variable 'b'
Undefined global functions or variables:
   . a b

a and b are iterators in foreach loops:

x <- foreach::foreach(a = A) %dopar% {some code}
y <- foreach::foreach(b = B) %do% {some code}

The dot is used in stats::update:

formula <- stats::update(formula, ~ . - 1)

This all works perfectly fine, and it is R CMD check that requires fixing, not the package. However, the repository maintainer refuses to accept the package unless I overcome this note. He recommended checking utils::globalVariables and I read the function's documentation and various discussions of it. What is not clear to me is whether utils::globalVariables(c("a", ".", "b")) would somehow interfere with the rest of my package? Would it affect the behavior or outcomes of the foreach loops or stats::update?

Chr
  • 1,017
  • 1
  • 8
  • 29
  • 2
    Yeah, everyone uses `utils::globalVariables()` to bypass the checks. I don't think it affects your output in any way. – F. Privé May 25 '21 at 11:30

0 Answers0