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

future.globals does not seem to work when variables are "created" in the named list #10

Closed
DavisVaughan opened this issue May 9, 2018 · 5 comments

Comments

@DavisVaughan
Copy link

DavisVaughan commented May 9, 2018

Kind of an obscure issue but definitely an issue:

library(future.apply)

plan(sequential)
future_lapply(
  X = 1, 
  FUN = function(x) {y}, 
  future.globals = list(y = 4)
)
#> Error in ...future.FUN(...future.X_jj, ...): object 'y' not found

z <- 1
future_lapply(
  X = 1, 
  FUN = function(x) {y}, 
  future.globals = list(y = z)
)
#> Error in ...future.FUN(...future.X_jj, ...): object 'y' not found

Created on 2018-05-09 by the reprex package (v0.2.0).

Interestingly, the y value is recognized as a global, and makes it into the environment that the expression is evaluated in. You can see this by debugging and making your way to this line of run.UniprocessFuture(). Not sure why it can't be seen inside the lapply() after that

@DavisVaughan
Copy link
Author

Seems to not be a problem with pure futures

library(future.apply)
#> Loading required package: future
#> 
#> Attaching package: 'future.apply'
#> The following object is masked from 'package:future':
#> 
#>     future_lapply
plan(sequential)
value(future({y}, globals = list(y = 4)))
#> [1] 4

value(future(
  expr = { lapply(1, function(x) {y}) }, 
  globals = list(y = 4)
))
#> [[1]]
#> [1] 4

Created on 2018-05-09 by the reprex package (v0.2.0).

@HenrikBengtsson
Copy link
Owner

HenrikBengtsson commented May 11, 2018

Thxs. Here's an example of the problem using plain futures:

> library(future)
> plan(sequential)
> f <- futureCall(function(x) y, args = list(x = 1), future.globals = list(y = 3))
> value(f)
Error in (function (x)  : object 'y' not found

It'll be solved over at HenrikBengtsson/future#225. Closing this one.

@HenrikBengtsson
Copy link
Owner

My futureCall() example was invalid. Re-opening this future.apply issue for now (though the solution to it will still be in the future package).

@DavisVaughan
Copy link
Author

FYI this affects multicore for me as well. multisession works though.

library(future.apply)

plan(multicore)
future_lapply(
  X = 1, 
  FUN = function(x) {y}, 
  future.globals = list(y = 4)
)
#> Error in ...future.FUN(...future.X_jj, ...): object 'y' not found

plan(multisession)
future_lapply(
  X = 1, 
  FUN = function(x) {y}, 
  future.globals = list(y = 4)
)
#> [[1]]
#> [1] 4

Created on 2018-05-14 by the reprex package (v0.2.0).

@HenrikBengtsson
Copy link
Owner

Turns out that I just fixed this in future (>= 1.21.0-9003) in HenrikBengtsson/future@6a87881, cf. HenrikBengtsson/future#515.

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

No branches or pull requests

2 participants