1

I am using R's excellent future package. And in the documentation it mentions %global% and %packages% for assigning global variables and packages to be evaluated in the future environment. But those seem to only work with %<-%.

My question is: is there away to do that with future_apply as well. I tried

x = 1
future.apply::future_sapply(1:50, function(y) {
  glue("{x}")
}) %packages% "glue" %globals% "x"

and It doesn't work

Michael Roswell
  • 1,300
  • 12
  • 31
xiaodai
  • 14,889
  • 18
  • 76
  • 140

1 Answers1

4

If you look at the help page for future_sapply, you'll see that future_lapply has the arguments future.packages and future.globals, and if you read carefully, these are also used in future_sapply. So this works:

x = 1
future.apply::future_sapply(1:50, function(y) {
  glue("{x}")
}, future.packages = "glue", future.globals = "x")
user2554330
  • 37,248
  • 4
  • 43
  • 90