[Rcpp-commits] r2268 - pkg/Rcpp/inst/doc/Rcpp-sugar

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Oct 4 13:24:37 CEST 2010


Author: edd
Date: 2010-10-04 13:24:36 +0200 (Mon, 04 Oct 2010)
New Revision: 2268

Modified:
   pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
Log:
addeded note to sugar vignette about RNGScope


Modified: pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2010-10-04 05:27:40 UTC (rev 2267)
+++ pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2010-10-04 11:24:36 UTC (rev 2268)
@@ -466,8 +466,25 @@
 
 One point to note is that the programmer using these functions needs to
 initialize the state of the random number generator as detailed in Section
-6.3 of the `Writing R Extensions' manual \citep{R:Extensions}.
+6.3 of the `Writing R Extensions' manual \citep{R:Extensions}.  A nice
+\proglang{C++} solution for this is to use a \textsl{scoped} class that sets
+the random number generatator on entry to a block and resets it on exit. We
+offer the \code{RNGScope} class which allows code such as
 
+<<lang=cpp>>=
+RcppExport SEXP getRGamma() {
+    RNGScope scope;
+    NumericVector x = rgamma( 10, 1, 1 );
+    return x;
+}
+@
+
+As there is some computational overhead involved in using \code{RNGScope}, we
+are not wrapping it around each inner function.  Rather, the user of these
+functions (\textsl{i.e.} you) should place an \code{RNGScope} at the
+appropriate level of your code.
+
+
 \section{Performance}
 \label{sec:performance}
 



More information about the Rcpp-commits mailing list