title: %dopar% error after several iterations
body: <p>I've been trying to get a parallelized foreach loop running in R, it works fine for approximately ten iterations but then crashes, showing the error:</p>
  
  <pre><code>Error in { : task 7 failed - "missing value where TRUE/FALSE needed"
  Calls: %dopar% -&gt; &lt;Anonymous&gt;
  Execution halted
  </code></pre>
  
  <p>I append the results of each loop to a file, which does show the output to be as expected. My script is as followed,using the combn_sub function from <a href="https://stackoverflow.com/questions/18292144/select-a-subset-of-combinations">this post</a>:</p>
  
  <pre><code>LBRA &lt;- fread(
   input      = "LBRA.012",
   data.table = FALSE)
  str_bra &lt;- nrow(LBRA)
  
  br1sums &lt;- colSums(LBRA)
  b1non &lt;- which(br1sums == 0)
  
  LBRA_trim &lt;- LBRA[,-b1non]
  
  library(foreach)
  library(doMC)
  registerDoMC(28)
  
  foreach(X = seq(2, (nrow(LBRA)-1))) %dopar% {
    com &lt;- combn_sub(
     x    = nrow(LBRA),
     m    = X,
     nset = 1000)
  
    out_in &lt;- matrix(
     ncol = 2,
     nrow = 1)
     colnames(out) &lt;- c("SNPs", "k")
  
      for (A in seq(1, ncol(com))){
        rowselect &lt;- com[, A]
  
        sub &lt;- LBRA_trim[rowselect, ]
        subsum &lt;- colSums(sub)
  
        length &lt;- length(which(subsum != 0)) - 1
        out_in &lt;- rbind(out_in, c(length, X))
      }
  
    write.table(
     file   = "plateau.csv",
     sep    = "\t",
     x      = out_in,
     append = TRUE)
  }
  </code></pre>