[Rcpp-commits] r3172 - pkg/Rcpp/inst/doc/Rcpp-sugar

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 16 03:23:41 CEST 2011


Author: edd
Date: 2011-08-16 03:23:41 +0200 (Tue, 16 Aug 2011)
New Revision: 3172

Modified:
   pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
Log:
fix missing wrap() in early example as per Darren Cook's email


Modified: pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2011-08-12 07:35:09 UTC (rev 3171)
+++ pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2011-08-16 01:23:41 UTC (rev 3172)
@@ -119,14 +119,15 @@
 RcppExport SEXP foo( SEXP xs, SEXP ys){
     Rcpp::NumericVector x(xs) ;
     Rcpp::NumericVector y(ys) ;
-    return ifelse( x < y, x*x, -(y*y) ) ;
+    return Rcpp::wrap( ifelse( x < y, x*x, -(y*y) )) ;
 }
 @
 
 Apart from the fact that we need to assign the two objects we obtain from
-\proglang{R}---which is a simple statement each thanks to the template magic in
-\pkg{Rcpp}---and the need for an explicit \texttt{return} statement, the code
-is now identical between highly-vectorised \proglang{R} and \proglang{C++}.
+\proglang{R}---which is a simple statement each thanks to the template magic
+in \pkg{Rcpp}---and the need for explicit \texttt{return} and
+\texttt{Rcpp::wrap} statements, the code is now identical between
+highly-vectorised \proglang{R} and \proglang{C++}.
 
 \sugar~is written using expression templates and lazy evaluation techniques
 \citep{Abrahams+Gurtovoy:2004:TemplateMetaprogramming,Vandevoorde+Josuttis:2003:Templates}.



More information about the Rcpp-commits mailing list