I had similar needs and found the simplest thing to do was to make the function on each worker node...<br><br>library(inline)<br>library(parallel)<br><br># A silly Rcpp function<br>silly.src <- '<br>  int x = as<int>(i);<br>
  double y = 5.6;<br>  NumericVector j(1);<br>  j[0] =  x + y;<br>  return j;<br>'<br><br>M <- detectCores()<br>cl <- makeCluster( M )<br><br># Load up Rcpp in each node.<br>clusterEvalQ( cl, require( inline ) )<br>
<br># Pass over the source.<br>clusterExport( cl, 'silly.src', .GlobalEnv )<br><br># Build it and keep the output for troubleshooting.<br>captured <- clusterEvalQ( cl, capture.output(<br>  silly <- cxxfunction( signature( i = "int" ),<br>
                        body = silly.src,<br>                        plugin = "Rcpp",<br>                        verbose= TRUE ) ) )<br><br># Use an explicit 'function' in the 'par' commands.<br>
res <- parSapply(cl, 1:10, function(x) { silly(x) } )<br><br>cat( unlist( captured ), sep='\n' )<br>print( res )<br><br>stopCluster(cl)<br>rm(cl)<br><br>rm( captured )<br>rm( res )<br><br clear="all"><br>-- <br>
Sincerely,<br>Thell<br>