How to pass rcmdcheck using generators
Hi all, I'm trying to use generators inside a library, but after declaring a generator and using it this happens:
f_iterator <- coro::generator(function(ret, from, to) {
for (id in seq(length(from))){
coro::yield(list(
from = from[[id]],
to = to[[id]],
distance = ret[[id]]
))
}
})
f_iterator : <anonymous>: no visible
binding for global variable ‘generator_env’
f_iterator : <anonymous>: no visible
binding for global variable ‘exits’
Undefined global functions or variables:
exits generator_env id
What is the right way to handle this?
Usually, with rcmdcheck, use global variables are more like a workaround than a proper fix.
Thx!
For now you'll need to use the globalVariables() workaround. We've working towards a better solution in https://bugs.r-project.org/show_bug.cgi?id=14354#c10
Hi!, mmm, reading it, there is something I can add to that bug.
But first, here is the workaround:
utils::globalVariables(c(
"generator_env",
"exits"
))
Now, about the declarations on tidyverse, like with .data or similar, you don't need to use the globalVariables, maybe a better alternative for rcmdcheck + tidyverse is the next one:
## manual namespace: end
## dplyr vars
#' @importFrom rlang .data
#' @importFrom rlang .env
## manual namespace: end
Still, is not a perfect solution, because .data and .env should only be valid inside a tidyverse function that uses it.
Thx!