私のコードは次のようになります。
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
最後の 4 行を実行すると、エラーが発生します。
l2<-(sfLapply(x, f1, list=x))
Error in checkForRemoteErrors(val) :
4 nodes produced errors; first error: could not find function "sfLapply"
lapplyを使用して順次処理に切り替えると、完全に実行されます。
> l2<-(lapply(x, f1, list=x))
> l2
[[1]]
[1] 10
[[2]]
[1] 7
[[3]]
[1] 6
[[4]]
[1] 7
[[5]]
[1] 10
sfLapply がエラーをスローするのはなぜですか?