<meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="font-family: &#39;Droid Sans&#39;, arial, sans-serif; font-size: 13px; border-collapse: collapse; color: rgb(32, 32, 32); ">Thanks Dirk.  Quick newbie followup question: Can we put functions within the inline C++ code?  The following doesn&#39;t compile, for example:<div>

<div>src &lt;- &#39;</div><div>int addition (int a, int b)</div><div>{</div><div>  int r;</div><div>  r=a+b;</div><div>  return (r);</div><div>}</div><div>NumericVector xx(x);</div><div>return(xx);</div><div>&#39;</div><div>

testfun = cxxfunction(signature(x=&quot;numeric&quot;),body=src,plugin=&quot;Rcpp&quot;)</div><div><br></div><div>On a related note, would you mind showing a quick working example using std::accumulate?  The one below from the quick reference doesn&#39;t compile for me.</div>

<div><br></div><div>Thanks in advance.</div><div>Chris</div><div><br></div><div>std::accumulate( xx.begin(), xx.end(),std::plus&lt;double&gt;(), 0.0 );</div></div></span><br><div class="gmail_quote">On Sat, May 14, 2011 at 2:54 PM, Dirk Eddelbuettel <span dir="ltr">&lt;<a href="mailto:edd@debian.org">edd@debian.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5"><br>
On 14 May 2011 at 14:11, Chris DuBois wrote:<br>
| I&#39;m just getting my feet wet with some Rcpp.  I&#39;m comfortable with R but new<br>
| to C++.  In the Rcpp vignettes, I found some of the R-like functions for<br>
| sampling from distributions (runif, rnorm, etc), but I didn&#39;t see a function<br>
| mimicking sample(). I checked the list of unit tests and didn&#39;t see it there<br>
| either.  Have I missed it?  Is there a C++ function I should be using to<br>
| sample (with replacement in my particular situation) from a vector (with<br>
| provided weights).<br>
<br>
</div></div>No, sorry, I think you&#39;d have to write a local version.<br>
<br>
Dirk<br>
<font color="#888888"><br>
--<br>
Gauss once played himself in a zero-sum game and won $50.<br>
                      -- #11 at <a href="http://www.gaussfacts.com" target="_blank">http://www.gaussfacts.com</a><br>
</font></blockquote></div><br>