[Rcpp-commits] r2704 - in pkg/Rcpp: . inst inst/doc/Rcpp-quickref
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Dec 4 12:46:45 CET 2010
Author: romain
Date: 2010-12-04 12:46:44 +0100 (Sat, 04 Dec 2010)
New Revision: 2704
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/THANKS
pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw
Log:
applying Christian's patch
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2010-12-04 11:26:04 UTC (rev 2703)
+++ pkg/Rcpp/ChangeLog 2010-12-04 11:46:44 UTC (rev 2704)
@@ -1,3 +1,8 @@
+2010-12-04 Romain Francois <romain at r-enthusiasts.com>
+
+ * inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw: documentation patch by
+ Christian Gunnning <xian at unm.edu>
+
2010-12-03 Dirk Eddelbuettel <edd at debian.org>
* inst/unitTests/runit.RObject.R: fix 'inherits' test added today
Modified: pkg/Rcpp/inst/THANKS
===================================================================
--- pkg/Rcpp/inst/THANKS 2010-12-04 11:26:04 UTC (rev 2703)
+++ pkg/Rcpp/inst/THANKS 2010-12-04 11:46:44 UTC (rev 2704)
@@ -3,6 +3,7 @@
Laurent Gautier for helpful discussions on R internals
Alistair Gee for a patch making ColDatum more robust
+Christian Gunning for a documentation patch
Uwe Ligges for help with Windows (32 and 64 bit) build issues
Tama Ma for a patch that extends Module constructors
Karl Millar for a patch helping with a non-g++ compiler
Modified: pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw 2010-12-04 11:26:04 UTC (rev 2703)
+++ pkg/Rcpp/inst/doc/Rcpp-quickref/Rcpp-quickref.Rnw 2010-12-04 11:46:44 UTC (rev 2704)
@@ -33,9 +33,11 @@
\maketitle
\thispagestyle{empty}
-% without the colon, latex does not want to newline
-\paragraph{Create simple vectors}: \newline
-
+% without the ~, latex does not want to newline
+% a newline between paragraph and code disconnects them and can orphan heading
+\paragraph{Create simple vectors}~
+ \newline
+ \newline
<<lang=cpp>>=
SEXP x; std::vector<double> y(10);
@@ -58,8 +60,9 @@
_["bar"] = 2.0 ); // short for Named
@
-\paragraph{Extract and set single elements}:\newline
-
+\paragraph{Extract and set single elements}~
+ \newline
+ \newline
<<lang=cpp>>=
// extract single values
double x0 = xx[0];
@@ -78,23 +81,26 @@
yy["foobar"] = 10.0;
@
-\paragraph{STL interface}:\newline
-
+\paragraph{STL interface}~
+ \newline
+ \newline
<<lang=cpp>>=
std::accumulate( xx.begin(), xx.end(),
std::plus<double>(), 0.0 );
int n = xx.size();
@
-\paragraph{Function}:\newline
-
+\paragraph{Function}~
+ \newline
+ \newline
<<lang=cpp>>=
Function rnorm("rnorm");
rnorm(100, _["mean"] = 10.2, _["sd"] = 3.2 );
@
-\paragraph{Environment}:\newline
-
+\paragraph{Environment}~
+ \newline
+ \newline
<<lang=cpp>>=
Environment stats("package:stats");
Environment env( 2 ); // by position
@@ -129,8 +135,9 @@
\newpage
-\paragraph{Rcpp sugar}:\newline
-
+\paragraph{Rcpp sugar}~
+ \newline
+ \newline
<<lang=cpp>>=
NumericVector x = NumericVector::create(
-2.0, -1.0, 0.0, 1.0, 2.0 );
@@ -164,6 +171,30 @@
IntegerVector yy = rev( y );
@
+\paragraph{Using matrices}~
+ \newline
+ \newline
+<<lang=cpp>>=
+// Initializing from SEXP,
+// dimensions handled automatically
+SEXP x;
+NumericMatrix xx(x);
+// Matrix of 4 rows & 5 columns (filled with 0)
+NumericMatrix xx(4, 5);
+
+// Fill with value
+int xsize = xx.nrow() * xx.ncol();
+for (int i = 0; i < xsize; i++) {
+ xx[i] = 7;
+}
+
+// Assign this value to single element
+// (1st row, 2nd col)
+xx(0,1) = 4;
+
+// Extract the second column
+NumericVector zz = xx( _, 1);
+@
+
\end{document}
-
More information about the Rcpp-commits
mailing list