title: How do I make doSMP play nicely with plyr?
body: <p>This code works:</p>
  
  <pre><code>library(plyr)
  x &lt;- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5)
  ddply(x, .(V), function(df) sum(df$Z),.parallel=FALSE) 
  </code></pre>
  
  <p>While this code fails:</p>
  
  <pre><code>library(doSMP)
  workers &lt;- startWorkers(2)
  registerDoSMP(workers)
  x &lt;- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5)
  ddply(x, .(V), function(df) sum(df$Z),.parallel=TRUE) 
  stopWorkers(workers)
  
  &gt;Error in do.ply(i) : task 3 failed - "subscript out of bounds"
  In addition: Warning messages:
  1: &lt;anonymous&gt;: ... may be used in an incorrect context: ‘.fun(piece, ...)’
  
  2: &lt;anonymous&gt;: ... may be used in an incorrect context: ‘.fun(piece, ...)’
  </code></pre>
  
  <p>I am using R 2.1.12, plyr 1.4 and doSMP 1.0-1.  Has anyone figured out a way around this?</p>
  
  <p>edit: In response to Andrie, here is a further illustration:</p>
  
  <pre><code>system.time(ddply(x, .(V), function(df) Sys.sleep(1), .parallel=FALSE)) #1
  system.time(ddply(x, .(V), function(df) Sys.sleep(1), .parallel=TRUE)) #2
  library(doSMP)
  workers &lt;- startWorkers(2)
  registerDoSMP(workers)
  x &lt;- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5)
  system.time(ddply(x, .(V), function(df) Sys.sleep(1), .parallel=FALSE)) #3
  system.time(ddply(x, .(V), function(df) Sys.sleep(1), .parallel=TRUE)) #4
  stopWorkers(workers)
  </code></pre>
  
  <p>The first three functions work, but they all take about 3 seconds.  Function #2 gives a warning that no parallel backend is registered, and thus executes sequentially.  Function #4 gives the same error I referenced in my original post.</p>
  
  <p>/edit: curioser and curiouser: On my mac, the following works:</p>
  
  <pre><code>library(plyr)
  library(doMC)
  registerDoMC()
  x &lt;- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5)
  ddply(x, .(V), function(df) sum(df$Z),.parallel=TRUE)
  </code></pre>
  
  <p>But this fails:</p>
  
  <pre><code>library(plyr)
  library(doSMP)
  workers &lt;- startWorkers(2)
  registerDoSMP(workers)
  x &lt;- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5)
  ddply(x, .(V), function(df) sum(df$Z),.parallel=TRUE) 
  stopWorkers(workers)
  </code></pre>
  
  <p>And this fails too:</p>
  
  <pre><code>library(plyr)
  library(snow)
  library(doSNOW)
  cl &lt;- makeCluster(2, type = "SOCK")
  registerDoSNOW(cl)
  x &lt;- data.frame(V= c("X", "Y", "X", "Y", "Z" ), Z = 1:5)
  ddply(x, .(V), function(df) sum(df$Z),.parallel=TRUE) 
  stopCluster(cl)
  </code></pre>
  
  <p>So I suppose the various parallel back ends for foreach are not interchangeable.</p>