Thanks for the pointer to sugar. <div><br></div><div>I was just trying to think of a simple example. So my C++ code will be essentially:</div><div><br></div><div>int main() {</div><div><br></div><div> RInside R(argc, argv); // create an embedded R instance </div>
<div> R.parseEval("X = generateSomeMatrix()");</div><div><br></div><div> Eigen::MatrixXd Xeigen;</div><div><br></div><div> // this is the part that I am still a bit unclear of:</div><div> // use Rcpp::as to make Xeigen take the value of X</div>
<div> </div><div>}<br><br><div class="gmail_quote">On Tue, Aug 7, 2012 at 2:34 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">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">
<br>
Also note that "just" getting random numbers is taken care of via Rcpp sugar<br>
which wraps rnorm() etc:<br>
<br>
R> library(inline)<br>
R><br>
R> R> f <- cxxfunction(signature(), plugin="Rcpp", body='<br>
+ Rcpp::RNGScope tmp;<br>
+ return rnorm(3);<br>
+ ')<br>
R><br>
R> set.seed(42)<br>
R> rnorm(3) ## using R<br>
[1] 1.370958 -0.564698 0.363128<br>
R> set.seed(42)<br>
R> f() ## using the Rcpp function just created<br>
[1] 1.370958 -0.564698 0.363128<br>
R><br>
<br>
Same RNG draws, as we deal properly with the RNG state (where RNGScope<br>
helps). Look at the list archives, this has been discussed a few times if<br>
it seems too "magic".<br>
<span class="HOEnZb"><font color="#888888"><br>
Dirk<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</div></div></blockquote></div><br></div>