My piece of code looks like:
x<- c(1,2,3,4,5)
library(snowfall)
f1<- function(a,list){
f2<-function(b,num){ return(abs(num-b))}
l1<-sfLapply(list, f2, num=a)
l1<-sum(unlist(l1))
return(l1)
}
sfInit(parallel=TRUE,cpus=4)
l2<-(sfLapply(x, f1, list=x))
sfStop()
l2
when I run the last four lines, it gives an error:
l2<-(sfLapply(x, f1, list=x))
Error in checkForRemoteErrors(val) :
4 nodes produced errors; first error: could not find function "sfLapply"
When I switch to sequential processing, using lapply, it runs perfectly.
> l2<-(lapply(x, f1, list=x))
> l2
[[1]]
[1] 10
[[2]]
[1] 7
[[3]]
[1] 6
[[4]]
[1] 7
[[5]]
[1] 10
Why is sfLapply throwing an error?