title: R Parallel processing error `Error in checkForRemoteErrors(val) : 6 nodes produced errors; first error: subscript out of bounds`
body: <p>I'm learning parallel processing as a way to handle some huge datasets. </p>
  
  <p>I have some variables predefined as below:  </p>
  
  <pre><code>CV &lt;- function(mean, sd) {(sd / mean) * 100} 
  distThreshold &lt;- 5 # Distance threshold 
  CVThreshold &lt;- 20 # CV threshold 
  
  LocalCV &lt;- list()
  Num.CV &lt;- list()
  </code></pre>
  
  <p>Then load <code>parallel</code> library, allocate the base variable and library to the clusters: </p>
  
  <pre><code>library(parallel)
  clust_cores &lt;- makeCluster(detectCores(logical = T) ) 
  clusterExport(clust_cores, c("i","YieldData2rd","CV", "distThreshold", "CVThreshold"))
  clusterEvalQ(clust_cores, library(sp))
  </code></pre>
  
  <p>Then pass the cluster argument <code>clust_cores</code> to <code>parSapply</code>:</p>
  
  <pre><code>for (i in seq(YieldData2rd)) {
    LocalCV[[i]] = parSapply(clust_cores, X = 1:length(YieldData2rd[[i]]), 
                     FUN = function(pt) {
                       d = spDistsN1(YieldData2rd[[i]], YieldData2rd[[i]][pt,])
                       ret = CV(mean = mean(YieldData2rd[[i]][d &lt; distThreshold, ]$yield), 
                                sd = sd(YieldData2rd[[i]][d &lt; distThreshold, ]$yield))
                       return(ret)
                     }) # calculate CV in the local neighbour 
  }
  
  stopCluster(clust_cores) 
  </code></pre>
  
  <p>Then I get <code>Error in checkForRemoteErrors(val) : 6 nodes produced errors; first error: subscript out of bounds</code> in addition to <code>warning messages:
  1: closing unused connection (&lt;-localhost:11688)</code>. </p>
  
  <p>Please let me know how to resolve this issue. </p>
  
  <p>For reproducible example, I create a large list object, which runs fine in the original <code>for</code> loop without the parallel processing components.  </p>
  
  <pre><code>library('rgdal')
  
  Yield1 &lt;- data.frame(yield=rnorm(460, mean = 10), x1=rnorm(460, mean = 1843235), x2=rnorm(460,mean = 5802532))
  Yield2 &lt;- data.frame(yield=rnorm(408, mean = 10), x1=rnorm(408, mean = 1843235), x2=rnorm(408, mean = 5802532))
  Yield3 &lt;- data.frame(yield=rnorm(369, mean = 10), x1=rnorm(369, mean = 1843235), x2=rnorm(369, mean = 5802532))
  
  coordinates(Yield1) &lt;- c('x1', 'x2')
  coordinates(Yield2) &lt;- c('x1', 'x2')
  coordinates(Yield3) &lt;- c('x1', 'x2')
  
  YieldData2rd &lt;- list(Yield1, Yield2, Yield3)
  </code></pre>