Thank you Christian!<div><br></div><div>Yes, I am doing exactly that. From previous e-mail archives, I have discovered that this is the advice that everyone gives.</div><div><br></div><div>As, I am on GNU/Linux, it seems (not sure) that it would be somewhat easier than it is on Windows.</div>
<div><br></div><div>Best Regards,</div><div>S.<br><br><div class="gmail_quote">On Mon, Jan 31, 2011 at 7:22 PM, Christian Gunning <span dir="ltr">&lt;<a href="mailto:xian@unm.edu">xian@unm.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">&gt; 2. I have a MCMC simulation (say: foo) which uses several functions (say:<br>
&gt; fun1, fun2). These functions (fun1, fun2) are themselves computation<br>
&gt; intensive and I used Rcpp to speed them. Until now I do something like this:<br>
&gt;<br>
&gt; In R file:<br>
&gt;<br>
&gt; foo &lt;- function (...){<br>
&gt;<br>
&gt;    src1 &lt;- paste(readLines(&quot;fun1-rcpp.cpp&quot;), collapse=&quot;\n&quot;)<br>
&gt;    RcppFun1 &lt;- cxxfunction( .., plugin=&quot;Rcpp&quot;,body=src1)<br>
&gt;<br>
</div><div class="im">&gt;   ## similar cpp code for fun2<br>
&gt;<br>
&gt;    for (i in 1:10000){<br>
&gt;          ## use RcppFun1, RcppFun2 here<br>
&gt;    }<br>
&gt; }<br>
<br>
</div>For MCMC, independence of loop iterations argues for explicit<br>
parallelism.  Assuming you have several cores available, look at the<br>
foreach package.  If you have several *machines*, each with many cores<br>
available, something like the snowfall package might make sense,<br>
depending on communication costs.<br>
<br>
<a href="http://cran.r-project.org/web/packages/multicore/index.html" target="_blank">http://cran.r-project.org/web/packages/multicore/index.html</a><br>
<a href="http://cran.r-project.org/web/packages/foreach/index.html" target="_blank">http://cran.r-project.org/web/packages/foreach/index.html</a><br>
<br>
<br>
It&#39;s &quot;yet another new thing&quot;, but as Dirk said, creating a package<br>
should help a lot for &quot;real work&quot;. See ?Rcpp.package.skeleton to get<br>
started, and the &quot;Writing R Extensions&quot; manual for details.  Exactly<br>
how to do this depends on OS (I don&#39;t know about windows shell), but<br>
the overview is:<br>
<br>
## 1. Start R in directory to contain myPackage and run the following<br>
&gt; Rcpp.package.skeleton(&quot;myPackage&quot;)<br>
<br>
## 2. edit code in myPackage/R and myPackage/src directories<br>
<br>
## 3. Run following commands from your OS shell,<br>
## in the directory from step 1 (just above the package directory)<br>
R CMD check myPackage  ## Optional<br>
R CMD INSTALL myPackage<br>
<br>
## 4. Start R from any directory and do<br>
&gt; require(myPackage)<br>
<br>
## 5. After editing code, you must exit R and repeat steps 3 and 4<br>
## to reload your package.<br>
<br>
best,<br>
Christian<br>
<font color="#888888">--<br>
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!<br>
</font></blockquote></div><br></div>