futureverse / future.apply

:rocket: R package: future.apply - Apply Function to Elements in Parallel using Futures
https://future.apply.futureverse.org
211 stars 16 forks source link

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

Closed sohappy1140937786 closed 1 year ago

sohappy1140937786 commented 1 year ago

(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 commented 1 year ago

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

sohappy1140937786 commented 1 year ago

Thank you!!!

HenrikBengtsson commented 1 year ago

You're welcome.