0

I have two functions myfunct1 and myfunct2. myfunct1 uses the myfunct2 function I want to use these two functions in a foreach()%dopar%{} loop but i get a error:

Error in {: task 1 failed - "unable to find function 'myfunct2'"

utils_u1.R

myfunct1 <- function(){return(myfunct2())}
myfunct2 <- function(){return(matrix(c("1", "2"), nrow = 1))}

fct_f1.R

#' @import doParallel parallel foreach
rbinddf <- function(){
  num_cores <- detectCores(); cl <- makeCluster(num_cores); registerDoParallel(cl)
  df <- foreach(i = 1:5, .combine = 'rbind', .export = c("myfunct1", "myfunct2")) %dopar% { return(myfunct1()) }
  stopCluster(cl)
  return(df)
}

app_server.R

app_server <- function(input, output, session) {
  print(rbinddf())
}
1

0

Browse other questions tagged or ask your own question.