[Rcpp-commits] r1893 - pkg/Rcpp/inst/doc/Rcpp-quickref

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 30 16:24:56 CEST 2010


Author: romain
Date: 2010-07-30 16:24:56 +0200 (Fri, 30 Jul 2010)
New Revision: 1893

Modified:
   pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw
Log:
some more

Modified: pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw	2010-07-30 13:26:14 UTC (rev 1892)
+++ pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw	2010-07-30 14:24:56 UTC (rev 1893)
@@ -31,11 +31,10 @@
 \thispagestyle{empty}
 
 % FIXME: without the dot, latex does not want to newline
-\paragraph{Simple Vectors}. \newline
+\paragraph{Create simple vectors}.\newline
 
 <<lang=cpp>>=
-SEXP x ; // from R
-std::vector<double> y(10) ;
+SEXP x ; std::vector<double> y(10) ;
 
 // from SEXP
 NumericVector xx(x) ;
@@ -50,8 +49,83 @@
 
 // using create
 NumericVector xx = NumericVector::create( 
-  1.0, 2.0, 3.0, 4.0 ) ;
+    1.0, 2.0, 3.0, 4.0 ) ;
+NumericVector yy = NumericVector::create( 
+    _["foo"] = 1.0, 
+    _["bar"] = 2.0 ) ;
 @
 
+\paragraph{Extract and set single elements}.\newline
+
+<<lang=cpp>>=
+// extract single values
+double x0 = xx[0] ;
+double x1 = xx(1) ;
+
+double y0 = yy["foo"] ;
+double y1 = yy["bar"] ;
+
+// set single values
+xx[0] = 2.1 ;
+xx(1) = 4.2 ;
+
+yy["foo"] = 3.0 ;
+
+// grow the vector
+yy["foobar"] = 10.0 ;
+@
+
+\paragraph{STL interface}.\newline
+
+<<lang=cpp>>=
+std::accumulate( xx.begin(), xx.end(), 
+    std::plus<double>(), 0.0 ) ;
+int n = xx.size() ;
+@
+
+\paragraph{Function}.\newline
+
+<<lang=cpp>>=
+Function rnorm("rnorm") ;
+rnorm(100, _["mean"] = 10.2, _["sd"] = 3.2 );
+@
+
+\paragraph{Environment}.\newline
+
+\begin{small}
+<<lang=cpp>>=
+Environment stats("package:stats") ;
+Environment env( 2 ) ; // by position
+
+// special environments
+Environment::Rcpp_namespace() ;
+Environment::base_env() ;
+Environment::base_namespace() ;
+Environment::global_env() ;
+Environment::empty_env() ;
+
+Function rnorm = stats["rnorm"] ;
+glob["x"] = "foo" ;
+glob["y"] = 3 ;
+std::string x = glob["x"] ;
+
+glob.assign( "foo" , 3 ) ;
+int foo = glob.get( "foo" ) ;
+int foo = glob.find( "foo" ) ;
+CharacterVector names = glob.ls()
+bool b = glob.exists( "foo" ) ;
+glob.remove( "foo" ) ;
+
+glob.lockBinding("foo") ;
+glob.unlockBinding("foo") ;
+bool b = glob.bindingIsLocked("foo") ;
+bool b = glob.bindingIsActive("foo") ;
+
+Environment e = stats.parent() ;
+Environment e = glob.new_child() ;
+@
+\end{small}
+
+
 \end{document}
 



More information about the Rcpp-commits mailing list