[Rcpp-commits] r3025 - in pkg/Rcpp: . inst inst/doc/Rcpp-quickref

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun May 15 03:16:06 CEST 2011


Author: edd
Date: 2011-05-15 03:16:05 +0200 (Sun, 15 May 2011)
New Revision: 3025

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS
   pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw
Log:
correct a mistake in Rcpp-quickref section on STL
added two other examples in that section


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2011-05-06 10:56:07 UTC (rev 3024)
+++ pkg/Rcpp/ChangeLog	2011-05-15 01:16:05 UTC (rev 3025)
@@ -1,3 +1,8 @@
+2011-05-14  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw: Corrected an error in STL
+	example and added two more STL examples
+
 2011-04-27  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/examples/OpenMP/piWithInterrupts.cpp: Beginnings of new

Modified: pkg/Rcpp/inst/NEWS
===================================================================
--- pkg/Rcpp/inst/NEWS	2011-05-06 10:56:07 UTC (rev 3024)
+++ pkg/Rcpp/inst/NEWS	2011-05-15 01:16:05 UTC (rev 3025)
@@ -5,6 +5,8 @@
         
     o   New sugar functions: mean, var, sd
 
+    o   Minor correction and extension to STL documentation in Rcpp-quickref
+
 0.9.4   2011-04-12
 
     o   New R function "loadRcppModules" to load Rcpp modules automatically

Modified: pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw	2011-05-06 10:56:07 UTC (rev 3024)
+++ pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw	2011-05-15 01:16:05 UTC (rev 3025)
@@ -201,9 +201,15 @@
 \paragraph{STL interface}~
   \newline
 <<lang=cpp>>=
-std::accumulate( xx.begin(), xx.end(),
-    std::plus<double>(), 0.0 );
-int n = xx.size();
+// sum a vector from beginning to end
+double s = std::accumulate(x.begin(),
+   x.end(), 0.0);
+// prod of elements from beginning to end
+int p = std::accumulate(vec.begin(),
+    vec.end(), 1, std::multiplies<int>());
+// inner_product to compute sum of squares
+double s2 = std::inner_product(res.begin(),
+    res.end(), res.begin(), 0.0);
 @
 
 \paragraph{Function}~
@@ -252,13 +258,13 @@
 <<lang=cpp>>=
 // Warning -- At present, module-based objects do not persist across quit(save="yes")/reload cycles.  To be safe, save results to R objects and remove module objects before exiting R.
 
-// To create a module-containing package from R, use: 
-Rcpp.package.skeleton("mypackage",module=TRUE) 
+// To create a module-containing package from R, use:
+Rcpp.package.skeleton("mypackage",module=TRUE)
 // You will need to edit the RcppModules: line of the DESCRIPTION file to match your module name (in this example, from yada to mod_bar).
 
 class Bar {
   public:
-    Bar(double x_) : 
+    Bar(double x_) :
       x(x_), nread(0), nwrite(0) {}
 
     double get_x( ) {
@@ -268,10 +274,10 @@
     void set_x( double x_) {
       nwrite++;   x = x_;
     }
-    
+
     IntegerVector stats() const {
       return IntegerVector::create(
-        _["read"] = nread, 
+        _["read"] = nread,
         _["write"] = nwrite);
     }
   private:
@@ -281,15 +287,15 @@
 RCPP_MODULE(mod_bar) {
   class_<Bar>( "Bar" )
   .constructor<double>()
-  .property( "x", &Bar::get_x, &Bar::set_x, 
+  .property( "x", &Bar::get_x, &Bar::set_x,
     "Docstring for x" )
-  .method( "stats", &Bar::stats, 
+  .method( "stats", &Bar::stats,
     "Docstring for stats")
 ;}
 
 ## The following is R code.
 require(mypackage); show(Bar)
-b <- new(Bar, 10);  b$x <- 10 
+b <- new(Bar, 10);  b$x <- 10
 b_persist <- list(stats=b$stats(), x=b$x)
 rm(b)
 @



More information about the Rcpp-commits mailing list