I am trying to use doParallel
for parallelising my query. I am trying to use the col_funcs
function within the same script bsp_functions.R
after it has been sourced.
#install.packages("doParallel")
library(doParallel)
cl <- makeCluster(3)
registerDoParallel(cl, cores=1)
path <- ("~/Combined/")
source(paste(path, "bsp_functions.R", sep=""))
res <- bsn(data=data, outcome=outcome)
#bsp_functions.R
bsn <- function(data, outcome){
rs_fun <- foreach(i=1:length(sets), .combine=rbind) %dopar% {
list['data.temp', 'sets'] <- col_funcs(data, set)
}
}
col_funcs <- function(data, set){
# processing
}
It is giving the below error:
Error:
Error in { : task 1 failed - "could not find function "col_funcs""
After looking at this post, I have changed my code as below by passing the function through .export
to global environment.
rs_fun <- foreach(i=1:length(sets), .combine=rbind, .export='col_funcs') %dopar% {
Now, it gave the below error.
Error in { :
task 1 failed - "object of type 'builtin' is not subsettable"
Any help would be appreciated.