title: Can't run Rcpp function in foreach - "NULL value passed as symbol address"
body: <p>Let me say first that I've read Writing R Extensions, the Rcpp package vignette, and that I've built a package from <code>Rcpp.package.skeleton()</code>.</p>
  
  <p>Since building my package, I added a function, <code>multiGenerateCSVrow()</code>, and then ran <code>compileAttributes()</code> on the package directory before R CMD build/R CMD install. After I load my package, I can run my function either directly or via <code>foreach()</code> with the <code>%do%</code> method.</p>
  
  <p>When I try to run in parallel however, I get an error:</p>
  
  <pre><code>cl &lt;- makePSOCKcluster(8)                                                                                     
  registerDoParallel(cl)                                                                                        
  rows &lt;- foreach(i=1:8,.combine=rbind,.packages="myPackage") %dopar% multiGenerateCSVrow(scoreMatrix=NIsample,   
                                                                     validMatrix = matrix(1,nrow=10,ncol=10),   
                                                                     cutoffVector = rep(0,10),                  
                                                                     factorVector = randomsCutPlus1[i,],        
                                                                     actualVector = rep(1,10),                  
                                                                     scaleSample = 1)                           
  stopCluster(cl)                                                                                               
  ~                                                                                                             
  
  Error in multiGenerateCSVrow(scoreMatrix = NIsample, validMatrix = matrix(1,  : 
    task 1 failed - "NULL value passed as symbol address"
  </code></pre>
  
  <p>Here's the package NAMESPACE:</p>
  
  <pre><code># Generated by roxygen2 (4.0.1): do not edit by hand 
  useDynLib(myPackage)                                   
  exportPattern("^[[:alpha:]]+")                       
  importFrom(Rcpp, evalCpp) 
  </code></pre>
  
  <p>Here's the relevant chunk of RcppExports.cpp:</p>
  
  <pre><code>// multiGenerateCSVrow
  SEXP multiGenerateCSVrow(SEXP scoreMatrix, SEXP validMatrix, SEXP cutoffVector, SEXP factorVector, SEXP actualVector, SEXP scaleSample);
  RcppExport SEXP myPackage_multiGenerateCSVrow(SEXP scoreMatrixSEXP, SEXP validMatrixSEXP, SEXP cutoffVectorSEXP, SEXP factorVectorSEXP, SEXP actualVectorSEXP, SEXP scaleSampleSEXP) {
  BEGIN_RCPP
      SEXP __sexp_result;
      {
          Rcpp::RNGScope __rngScope;
          Rcpp::traits::input_parameter&lt; SEXP &gt;::type scoreMatrix(scoreMatrixSEXP );
          Rcpp::traits::input_parameter&lt; SEXP &gt;::type validMatrix(validMatrixSEXP );
          Rcpp::traits::input_parameter&lt; SEXP &gt;::type cutoffVector(cutoffVectorSEXP );
          Rcpp::traits::input_parameter&lt; SEXP &gt;::type factorVector(factorVectorSEXP );
          Rcpp::traits::input_parameter&lt; SEXP &gt;::type actualVector(actualVectorSEXP );
          Rcpp::traits::input_parameter&lt; SEXP &gt;::type scaleSample(scaleSampleSEXP );
          SEXP __result = multiGenerateCSVrow(scoreMatrix, validMatrix, cutoffVector, factorVector, actualVector, scaleSample);
          PROTECT(__sexp_result = Rcpp::wrap(__result));
      }
      UNPROTECT(1);
      return __sexp_result;
  END_RCPP
  }
  </code></pre>
  
  <p>And RcppExports.R:</p>
  
  <pre><code>multiGenerateCSVrow &lt;- function(scoreMatrix, validMatrix, cutoffVector, factorVector, actualVector, scaleSample) {
      .Call('myPackage_multiGenerateCSVrow', PACKAGE = 'myPackage', scoreMatrix, validMatrix, cutoffVector, factorVector, actualVector, scaleSample)
  }   
  </code></pre>
  
  <p>What could it be looking for?</p>