[Rcpp-commits] r4144 - in pkg/Rcpp: . inst inst/include/Rcpp inst/include/Rcpp/sugar/functions inst/include/Rcpp/sugar/functions/strings inst/include/Rcpp/vector
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Dec 11 09:25:19 CET 2012
Author: romain
Date: 2012-12-11 09:25:19 +0100 (Tue, 11 Dec 2012)
New Revision: 4144
Added:
pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/
pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/collapse.h
pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/strings.h
Modified:
pkg/Rcpp/ChangeLog
pkg/Rcpp/inst/NEWS.Rd
pkg/Rcpp/inst/include/Rcpp/String.h
pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h
Log:
collapse sugar function
Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog 2012-12-11 07:43:27 UTC (rev 4143)
+++ pkg/Rcpp/ChangeLog 2012-12-11 08:25:19 UTC (rev 4144)
@@ -1,6 +1,9 @@
2012-12-11 Romain Francois <romain at r-enthusiasts.com>
- * include/String.h: missing operator +=( const StringProxy& )
+ * include/Rcpp/String.h: missing operator +=( const StringProxy& )
+ * include/Rcpp/sugar/functions/strings/strings.h : string sugar functions
+ * include/Rcpp/sugar/functions/strings/collapse.h : collapse function,
+ implementing paste( . , collapse = "" )
2012-12-10 JJ Allaire <jj at rstudio.org>
Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd 2012-12-11 07:43:27 UTC (rev 4143)
+++ pkg/Rcpp/inst/NEWS.Rd 2012-12-11 08:25:19 UTC (rev 4144)
@@ -22,6 +22,7 @@
\item More efficient version of \code{in} base on \code{IndexHash}
\item More efficient version of \code{duplicated} base on \code{IndexHash}
\item More efficient version of \code{self_match} base on \code{IndexHash}
+ \item New function \code{collapse} that implements paste(., collapse= "" )
}
\item Changes in Rcpp attributes:
\itemize{
Modified: pkg/Rcpp/inst/include/Rcpp/String.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/String.h 2012-12-11 07:43:27 UTC (rev 4143)
+++ pkg/Rcpp/inst/include/Rcpp/String.h 2012-12-11 08:25:19 UTC (rev 4144)
@@ -125,16 +125,20 @@
SEXP proxy_sexp = proxy ;
if( proxy_sexp == NA_STRING ) { data = NA_STRING ; valid = true; buffer_ready = false ; return *this ;}
setBuffer() ; buffer += CHAR(proxy_sexp) ; valid = false ;
- RCPP_STRING_DEBUG_1( "String::operator+=( const StringProxy& ), buffer = %s", buffer.c_str() ) ;
return *this ;
}
-
+ inline String& operator+=( SEXP x){
+ RCPP_STRING_DEBUG( "String::operator+=( SEXP )" ) ;
+ if( is_na() ) return *this ;
+ if( x == NA_STRING ) { data = NA_STRING ; valid = true; buffer_ready = false ; return *this ;}
+ setBuffer() ; buffer += CHAR(x) ; valid = false ;
+ return *this ;
+ }
// inline String& operator+=( int x ){ data += char_nocheck(internal::r_coerce<INTSXP ,STRSXP>( x ) ) ; return *this ; }
// inline String& operator+=( double x ){ data += char_nocheck(internal::r_coerce<REALSXP,STRSXP>( x ) ) ; return *this ; }
// inline String& operator+=( Rbyte x ){ data += char_nocheck(internal::r_coerce<RAWSXP ,STRSXP>( x ) ) ; return *this ; }
// inline String& operator+=( bool x ){ data += char_nocheck(internal::r_coerce<LGLSXP ,STRSXP>( x ) ) ; return *this ; }
// inline String& operator+=( Rcomplex x){ data += char_nocheck(internal::r_coerce<CPLXSXP,STRSXP>( x ) ) ; return *this ; }
- // inline String& operator+=( SEXP x){ data += CHAR(x) ; return *this ; }
inline String& replace_first( const char* s, const char* news ){
Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h 2012-12-11 07:43:27 UTC (rev 4143)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/functions.h 2012-12-11 08:25:19 UTC (rev 4144)
@@ -68,4 +68,6 @@
#include <Rcpp/sugar/functions/self_match.h>
#include <Rcpp/sugar/functions/setdiff.h>
+#include <Rcpp/sugar/functions/strings/strings.h>
+
#endif
Added: pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/collapse.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/collapse.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/collapse.h 2012-12-11 08:25:19 UTC (rev 4144)
@@ -0,0 +1,46 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// collapse.h: Rcpp R/C++ interface class library -- string sugar functions
+//
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef RCPP_SUGAR_FUNCTIONS_COLLAPSE_H
+#define RCPP_SUGAR_FUNCTIONS_COLLAPSE_H
+
+namespace Rcpp{
+ namespace sugar {
+ template <typename Iterator>
+ inline String collapse__impl( Iterator it, int n ){
+ static String buffer ;
+ buffer = "" ;
+ for( int i=0; i<n; i++ ){
+ buffer += it[i] ;
+ }
+ return buffer ;
+ }
+
+ } // sugar
+
+
+ template <bool NA, typename T>
+ inline String collapse( const VectorBase<STRSXP,NA,T>& vec ){
+ return sugar::collapse__impl( vec.get_ref().begin(), vec.size() ) ;
+ }
+
+}
+#endif
Added: pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/strings.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/strings.h (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/strings/strings.h 2012-12-11 08:25:19 UTC (rev 4144)
@@ -0,0 +1,27 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
+//
+// strings.h: Rcpp R/C++ interface class library -- string sugar functions
+//
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
+//
+// This file is part of Rcpp.
+//
+// Rcpp is free software: you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 2 of the License, or
+// (at your option) any later version.
+//
+// Rcpp is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef RCPP_SUGAR_FUNCTIONS_STRINGS_H
+#define RCPP_SUGAR_FUNCTIONS_STRINGS_H
+
+#include <Rcpp/sugar/functions/strings/collapse.h>
+
+#endif
Modified: pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h 2012-12-11 07:43:27 UTC (rev 4143)
+++ pkg/Rcpp/inst/include/Rcpp/vector/MatrixRow.h 2012-12-11 08:25:19 UTC (rev 4144)
@@ -82,7 +82,7 @@
bool operator<=( const iterator& other ) { return index <= other.index ; }
bool operator>=( const iterator& other ) { return index >= other.index ; }
- inline reference operator[]( int i){
+ inline reference operator[]( int i) const {
return row[ index + i ] ;
}
More information about the Rcpp-commits
mailing list