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

Use of variables in glue() inside furrr loops #262

Closed
MS-equinom opened this issue Aug 16, 2023 · 1 comment
Closed

Use of variables in glue() inside furrr loops #262

MS-equinom opened this issue Aug 16, 2023 · 1 comment

Comments

@MS-equinom
Copy link

Hi

When the first time a global variable appears in a furrr function is in a glue expression, the loop fails with error object XXX not found.

Example:

library(furrr)
plan(multisession, workers = 2)
options(future.scheduling = 2L)
    

t1<- "sdsdsd"
furrr::future_walk(1:4,.f = function(x) {
    t2 <- glue::glue("{t1}")
    print(t2)
    })

However, adding print(t1) anywhere in the loop will make the code work.

I assume this is because furrr shares with the workers only those global variables that are used in the loop, and that it does not recognize variables inside glue expressions as variables to be shared.

Thanks for the awesome furrr package. Love it.

@DavisVaughan
Copy link
Owner

it does not recognize variables inside glue expressions as variables to be shared.

Yea, this is exactly right. Since it is embedded in a string the {globals} package can't "find" that t1 needs to be exported.

This is actually listed as one of the "common gotchas"
https://future.futureverse.org/articles/future-4-issues.html#glueglue---object-not-found

If you add t1 manually through furrr_options() then it will find it

furrr::future_walk(1:4, .f = function(x) {
  t2 <- glue::glue("{t1}")
  print(t2)
}, .options = furrr::furrr_options(globals = "t1"))

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