[Rcpp-commits] r2263 - papers/rjournal
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Oct 2 16:27:21 CEST 2010
Author: edd
Date: 2010-10-02 16:27:17 +0200 (Sat, 02 Oct 2010)
New Revision: 2263
Modified:
papers/rjournal/EddelbuettelFrancois.tex
Log:
make snippet a function (as discussed in emails) to make it clearer what
returns does
some jugging some code comments too to keep page breaks
Modified: papers/rjournal/EddelbuettelFrancois.tex
===================================================================
--- papers/rjournal/EddelbuettelFrancois.tex 2010-10-01 05:26:12 UTC (rev 2262)
+++ papers/rjournal/EddelbuettelFrancois.tex 2010-10-02 14:27:17 UTC (rev 2263)
@@ -358,21 +358,23 @@
\code{Rcpp-extending} vignette discusses in depth how to extend \code{wrap}
to third-party types. The \pkg{RcppArmadillo} package
\citep*{CRAN:RcppArmadillo} features several examples.
-
-The following code snippet illustrates that the design allows
+%
+The following example shows that the design allows
composition:
\begin{example}
-std::vector< std::map<std::string,int> > v;
-std::map< std::string, int > m1;
-std::map< std::string, int > m2;
+SEXP someFunction() {
+ std::vector< std::map<std::string,int> > v;
+ std::map< std::string, int > m1;
+ std::map< std::string, int > m2;
-m1["foo"] = 1; m1["bar"] = 2;
-m2["foo"] = 1; m2["bar"] = 2; m2["baz"] = 3;
+ m1["foo"] = 1; m1["bar"] = 2;
+ m2["foo"] = 1; m2["bar"] = 2; m2["baz"] = 3;
-v.push_back( m1);
-v.push_back( m2);
-Rcpp::wrap( v );
+ v.push_back( m1);
+ v.push_back( m2);
+ Rcpp::wrap( v );
+}
\end{example}
The code creates a list of two named vectors, equal to the
@@ -415,18 +417,14 @@
interchange data between C++ and R.
\begin{example}
-// assuming the global environment contains
-// a variable 'x' that is a numeric vector
+// access vector 'x' from global env.
Rcpp::Environment global =
\ \ \ \ Rcpp::Environment::global_env();
-
-// extract a std::vector<double> from
-// the global environment
std::vector<double> vx = global["x"];
// create a map<string,string>
std::map<std::string,std::string> map;
-map["foo"] = "oof";
+map["foo"] = "oof";
map["bar"] = "rab";
// push the STL map to R
More information about the Rcpp-commits
mailing list