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

Error in parallel execution using future_lapply with R6 objects and the get() function Description: #114

Closed
sohappy1140937786 opened this issue Jun 27, 2023 · 3 comments

Comments

@sohappy1140937786
Copy link

(Please use https://github.com/HenrikBengtsson/future/discussions for Q&A)

Describe the bug

I am encountering an issue while attempting to perform parallel execution using in R. The parallel execution seems to be missing global variables when working with R6 objects.future_lapply.
Reproduce example
`library(R6)

Person1 <- R6Class(
"Person1",
public = list(
name = NA,
initialize = function(name) {
self$name <- name
},
say = function() {
cat("my name is ", self$name)
}
)
)

get1 <- function(name) {
obj <- get(name)
aa <- obj$new("bob")
return(aa)
}

data <- tribble(
~a,
"Person1",
"Person2"
)

library(future.apply)
library(future)

ls()
#[1] "data" "get1" "Person1"

plan(multisession)

model <- future_lapply(1:nrow(data), function(i) {
plsRcox_obj_a <- get1(data[[i, "a"]])
})
#Error in get(name) : object 'person1' not found
`

Expected behavior
Expected Behavior:
I expect that the function would correctly utilize the global variables and create instances of the R6 objects ( and ) in parallel.future_lapplyPerson1Person2
#101

> sessionInfo()
@HenrikBengtsson
Copy link
Collaborator

Please see https://future.futureverse.org/articles/future-4-issues.html#get---object-not-found.

@sohappy1140937786
Copy link
Author

Thank you!!!

@HenrikBengtsson
Copy link
Collaborator

You're welcome.

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

No branches or pull requests

2 participants