[Rcpp-commits] r843 - in pkg: Rcpp RcppExamples RcppExamples/src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 7 12:22:25 CET 2010
Author: romain
Date: 2010-03-07 12:22:24 +0100 (Sun, 07 Mar 2010)
New Revision: 843
Modified:
pkg/Rcpp/DESCRIPTION
pkg/RcppExamples/DESCRIPTION
pkg/RcppExamples/src/RcppStringVectorExample.cpp
Log:
use a local class instead of a local function
Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION 2010-03-07 11:17:51 UTC (rev 842)
+++ pkg/Rcpp/DESCRIPTION 2010-03-07 11:22:24 UTC (rev 843)
@@ -1,6 +1,6 @@
Package: Rcpp
Title: Rcpp R/C++ interface package
-Version: 0.7.7.12
+Version: 0.7.7.13
Date: $Date$
Author: Dirk Eddelbuettel and Romain Francois, with contributions
by Simon Urbanek and David Reiss; based on code written during
Modified: pkg/RcppExamples/DESCRIPTION
===================================================================
--- pkg/RcppExamples/DESCRIPTION 2010-03-07 11:17:51 UTC (rev 842)
+++ pkg/RcppExamples/DESCRIPTION 2010-03-07 11:22:24 UTC (rev 843)
@@ -8,7 +8,7 @@
Description: Examples for Seamless R and C++ integration
The Rcpp package contains a C++ library that facilitates the integration of
R and C++ in various ways. This package provides examples.
-Depends: R (>= 2.10.0), Rcpp (>= 0.7.7)
+Depends: R (>= 2.10.0), Rcpp (>= 0.7.7.14)
Suggests: inline (>= 0.3.4), RUnit
SystemRequirements: None
URL: http://dirk.eddelbuettel.com/code/rcpp.html, http://romainfrancois.blog.free.fr/index.php?category/R-package/Rcpp
Modified: pkg/RcppExamples/src/RcppStringVectorExample.cpp
===================================================================
--- pkg/RcppExamples/src/RcppStringVectorExample.cpp 2010-03-07 11:17:51 UTC (rev 842)
+++ pkg/RcppExamples/src/RcppStringVectorExample.cpp 2010-03-07 11:22:24 UTC (rev 843)
@@ -23,28 +23,31 @@
#include <Rcpp.h>
-// local helper function to transform all characters of a given string
-void stringToLower(std::string & s) {
- std::transform(s.begin(), s.end(), s.begin(), ::tolower);
-}
+// local helper class to transform all characters of a given string
+class StringToLower{
+public:
+ StringToLower() : buffer() {}
+ ~StringToLower(){}
+
+ std::string operator()( const char* input){
+ buffer = input ;
+ std::transform( buffer.begin(), buffer.end(), buffer.begin(), ::tolower);
+ return buffer ;
+ }
+private:
+ std::string buffer ;
+} ;
RcppExport SEXP newRcppStringVectorExample(SEXP strvec) {
Rcpp::StringVector orig(strvec); // creates Rcpp string vector from SEXP
Rcpp::StringVector vec(orig.size());
- std::string txt;
- for (int i=0; i<orig.size(); i++) {
- txt = orig[i];
- stringToLower(txt);
- vec[i] = txt;
- }
- //std::transform(orig.begin(), orig.end(), vec.begin(), stringToLower);
- //std::for_each(vec.begin(), vec.end(), stringToLower);
-
+ std::transform( orig.begin(), orig.end(), vec.begin(), StringToLower() ) ;
- Rcpp::Pairlist res(Rcpp::Named( "result", vec),
- Rcpp::Named( "original", orig));
+ Rcpp::Pairlist res(
+ Rcpp::Named( "result" ) = vec,
+ Rcpp::Named( "original" ) = orig ) ;
return res;
}
More information about the Rcpp-commits
mailing list