-
Notifications
You must be signed in to change notification settings - Fork 39
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
furrr functions within functions #26
Comments
First off, are you on Windows or Mac or Linux? What |
Apols, should have specified those already. I am on Windows and use plan(multisession)
|
@HenrikBengtsson, I thought you might be interested in this too as it affects library(future.apply)
plan(multisession)
test_fn <- function() {
x <- c(1,2)
y <- 2
future_lapply(
X = x,
FUN = function(.x) .x + y, # <- this y should not be exported?
future.globals = "x"
)
}
test_fn()
#> [[1]]
#> [1] 3
#>
#> [[2]]
#> [1] 4
# Where is that y?
test_fn_envs <- function() {
x <- c(1,2)
y <- 2
# return the envs of those processes
future_lapply(
X = x,
FUN = function(.x) {
.x + y
env <- environment()
parent_env <- parent.env(env)
return(list(this_env = env, parent_env = parent_env))
},
future.globals = "x"
)
}
ret <- test_fn_envs()
names(ret[[1]]$this_env)
#> [1] "parent_env" "env" ".x"
names(ret[[1]]$parent_env) # <- here is the y, function scoping rules find it in FUN
#> [1] "y" "x" Created on 2018-09-01 by the reprex |
My thoughts on this are, the anonymous |
This is definitely bad because @vrontosc's concerns are valid, any object in that function will be exported, whether it is used in library(future.apply)
plan(multisession)
test_fn_envs <- function() {
x <- c(1,2)
y <- 2
really_large_thing <- 1
# return the envs of those processes
future_lapply(
X = x,
FUN = function(.x) {
.x + y
env <- environment()
parent_env <- parent.env(env)
return(list(this_env = env, parent_env = parent_env))
},
future.globals = "x"
)
}
ret <- test_fn_envs()
names(ret[[1]]$parent_env) # <- really_large_thing came through
#> [1] "really_large_thing" "y" "x" Created on 2018-09-01 by the reprex |
I am also trying to use Are there any updates on this issue? Can you suggest a workaround in the meantime for those of us that want to run things in parallel inside our own function with |
Hi Davis,
Apologies for the question cause I am clearly missing something here and I would appreciate your help in understanding the usage of furrr functions within functions.
The below function fails and I do understand that this is the expected behavior
However in the below example it seems to be working fine and I don't really understand why all the objects defined within a function are essentially deemed to be "globals".
The problem I am facing with this is that I may have sizable objects in my function but I don't want them to be exported to every worker as it materially degrades performance.
The text was updated successfully, but these errors were encountered: