Skip to content
Prev 2359 / 10988 Next

[Rcpp-devel] R.e.: Problems with rlnorm

On Sun, May 29, 2011 at 3:29 PM,
<rcpp-devel-request at r-forge.wu-wien.ac.at> wrote:
Take a look at the quickref in the section "Using matrices",
particularly the part about "_" -- Romain has done a lot of work since
the conversation that you reference :)
Also, see previous list message from Vincent and Dirk for namespace
notes on using _ outside of inline.
It's working now in the most recent SVN version (I'm guessing
someone's already pointed this out).

Below is an example that includes by-column assignment.  Also, unless
you need to reset the seed mid-function-call, RNGScope grabs the seed
from R, so you can use a regular set.seed call.  So, the return value
of the following is identical to that of your example:

require(inline)
src <- '
Rcpp::RNGScope Scope; // gets value from set.seed call in R
int NumRands = 5;
int NumTrials = 3;
Rcpp::NumericMatrix RandVals(NumRands, NumTrials*2);
RandVals(_,3)=rlnorm(NumRands,2.0,1.0);
return RandVals;
'
 fun1 <- cxxfunction(signature(),
 src, plugin = "Rcpp")

set.seed(20)
fun1()

-Christian