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)
}
)
)
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
(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