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
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")