Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass rcmdcheck using generators #40

Open
latot opened this issue Sep 6, 2023 · 2 comments
Open

How to pass rcmdcheck using generators #40

latot opened this issue Sep 6, 2023 · 2 comments

Comments

@latot
Copy link

latot commented Sep 6, 2023

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 variablegenerator_envf_iterator : <anonymous>: no visible
    binding for global variableexitsUndefined 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!

@lionel-
Copy link
Member

lionel- commented Sep 6, 2023

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

@latot
Copy link
Author

latot commented Sep 6, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants