HenrikBengtsson / doFuture

:rocket: R package: doFuture - Use Foreach to Parallelize via Future Framework
https://doFuture.futureverse.org
84 stars 6 forks source link

Search for globals also in data object iterated over #27

Closed HenrikBengtsson closed 5 years ago

HenrikBengtsson commented 6 years ago

As in future.apply, cf. Issue https://github.com/HenrikBengtsson/future.apply/issues/12

HenrikBengtsson commented 5 years ago

A small reproducible example:

library("doFuture")
registerDoFuture()

a <- 42
b <- 21
X <- list(function(b) 2 * a, function() b / 2, function() a + b, function() 3.14)

plan(sequential)
y <- foreach(f = X) %dopar% f()
str(y)
List of 4
 $ : num 84
 $ : num 10.5
 $ : num 63
 $ : num 3.14

plan(multisession, workers = 2L)
y <- foreach(f = X) %dopar% f()
## Error in { : task 1 failed - "object 'a' not found"