[Rcpp-commits] r3024 - in pkg/Rcpp/inst/doc: Rcpp-modules Rcpp-quickref

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri May 6 12:56:07 CEST 2011


Author: edd
Date: 2011-05-06 12:56:07 +0200 (Fri, 06 May 2011)
New Revision: 3024

Modified:
   pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
   pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw
Log:
another Rcpp-quickref patch by Christian
as well as a small bug fix to Rcpp-modules too


Modified: pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2011-04-27 13:58:47 UTC (rev 3023)
+++ pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2011-05-06 10:56:07 UTC (rev 3024)
@@ -784,7 +784,8 @@
     private:
         double x;
         int nread, nwrite;
-}
+};
+
 RCPP_MODULE(mod_bar) {
     class_<Bar>( "Bar" )
 

Modified: pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw	2011-04-27 13:58:47 UTC (rev 3023)
+++ pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw	2011-05-06 10:56:07 UTC (rev 3024)
@@ -247,6 +247,53 @@
 Environment e = glob.new_child();
 @
 
+\paragraph{Modules}~
+  \newline
+<<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) 
+// 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_) : 
+      x(x_), nread(0), nwrite(0) {}
+
+    double get_x( ) {
+      nread++;    return x;
+    }
+
+    void set_x( double x_) {
+      nwrite++;   x = x_;
+    }
+    
+    IntegerVector stats() const {
+      return IntegerVector::create(
+        _["read"] = nread, 
+        _["write"] = nwrite);
+    }
+  private:
+    double x; int nread, nwrite;
+};
+
+RCPP_MODULE(mod_bar) {
+  class_<Bar>( "Bar" )
+  .constructor<double>()
+  .property( "x", &Bar::get_x, &Bar::set_x, 
+    "Docstring for x" )
+  .method( "stats", &Bar::stats, 
+    "Docstring for stats")
+;}
+
+## The following is R code.
+require(mypackage); show(Bar)
+b <- new(Bar, 10);  b$x <- 10 
+b_persist <- list(stats=b$stats(), x=b$x)
+rm(b)
+@
+
 \newpage
 
 \paragraph{Rcpp sugar}~



More information about the Rcpp-commits mailing list