<meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="font-family: 'Droid Sans', 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't compile, for example:<div>
<div>src <- '</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>'</div><div>
testfun = cxxfunction(signature(x="numeric"),body=src,plugin="Rcpp")</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'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<double>(), 0.0 );</div></div></span><br><div class="gmail_quote">On Sat, May 14, 2011 at 2:54 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org">edd@debian.org</a>></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'm just getting my feet wet with some Rcpp. I'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't see a function<br>
| mimicking sample(). I checked the list of unit tests and didn'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'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>