title: Parallel computing in R on Windows using doSNOW: How to transfer results from clusters back to master
body: <p>When using clusters in R on Windows I been trying to find a simple way to transfer results from a cluster to the master. If the results is an array or a simple number the .combine option of  foreach / %dopar% statement takes care of this, but if the result is a complex object lets such a randomForest model, how to transfer the whole model from the slave cluster back to the master?</p>
  
  <p>I try: assing with <code>env=.Global</code> but it does not work on my Windows 7.</p>
  
  <p>At the end I work around by saving the object to file. Then the master can recover the object. If someone knows a more elegant way or why assing does not work I appreciate comments.</p>
  
  <p>sample code:</p>
  
  <pre><code>print(" paralelize with 8 cores ------------------------------")
  library(doSNOW)
  cl&lt;-makeCluster(8)
  registerDoSNOW(cl)
  clusterEvalQ(cl, library(randomForest))
  clusterExport(cl, "x")
  clusterExport(cl, "y")
  clusterExport(cl, "x.selected")
  
  makeModel &lt;- function(i){
    m &lt;- randomForest(x,x.selected[i,],mtry=250,sampsize=3200,ntree = 3000,do.trace=TRUE) 
    eval(parse(text = paste("model_",i," &lt;- m",sep="")))
    eval(parse( text =paste("save(model_", i, ", file =\"model_", i, ".Rdata\")",sep="" ) ))
  }
  
  foreach(i = 1:length(x.selected[,1]),.verbose = TRUE ) %dopar% makeModel(i)
  stopCluster(cl)
  
  foreach(i = 1:length(x.selected[,1]),.verbose = TRUE ) %do% 
  load(paste("model_",i,".RData",sep=""))
  </code></pre>