[Rcpp-commits] r4343 - in pkg/Rcpp: . inst inst/include/Rcpp/vector inst/unitTests inst/unitTests/cpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 19 15:03:51 CEST 2013


Author: romain
Date: 2013-06-19 15:03:50 +0200 (Wed, 19 Jun 2013)
New Revision: 4343

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
   pkg/Rcpp/inst/unitTests/cpp/Vector.cpp
   pkg/Rcpp/inst/unitTests/runit.Vector.R
Log:
character vector element equality operator

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-06-18 17:08:35 UTC (rev 4342)
+++ pkg/Rcpp/ChangeLog	2013-06-19 13:03:50 UTC (rev 4343)
@@ -1,3 +1,9 @@
+2013-06-19 Romain Francois <romain at r-enthusiasts.com>
+
+        * include/Rcpp/vector/string_proxy.h : added operator
+        string_proxy::operator==( const string_proxy& ) so that me may compare x[i]
+        and y[i] (x and y being CharacterVector)
+        
 2013-06-18 Romain Francois <romain at r-enthusiasts.com>
 
         * include/Rcpp/module/Module_generated_CppFunction.h : using BEGIN_RCPP / END_RCPP

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2013-06-18 17:08:35 UTC (rev 4342)
+++ pkg/Rcpp/inst/NEWS.Rd	2013-06-19 13:03:50 UTC (rev 4343)
@@ -28,7 +28,8 @@
       \item \code{Vector<*>::erase(iterator, iterator)} was fixed. Now
       it does not remove the element pointed by last (similar to what is
       done on stl types and what was intended initially). Reported on
-      Rcpp-devel by Toni Giorgino.  
+      Rcpp-devel by Toni Giorgino.
+      \item Added equality operator between elements of \code{CharacterVector}s. 
     }
     \item Changes in Rcpp sugar:
     \itemize{
@@ -48,10 +49,20 @@
     }
     \item Changes in Rcpp documentation:
     \itemize{
-      \item Updated the bibliograph in \code{Rcpp.bib} (which is also
+      \item Updated the bibliography in \code{Rcpp.bib} (which is also
       sourced by packages using Rcpp).
       \item Updated the \code{THANKS} file.
     }
+    \item Deprecation plans:
+    \itemize{
+      \item The set of macros \code{RCPP_FUNCTION_} etc ... from the 
+      \code{preprocessor_generated.h} file will be deprecated in the next version
+      of \code{Rcpp}, i.e they willl still be available but will generate some
+      warning in addition to their expected behavior. 
+      In release +2 the macros will be removed
+      from \code{Rcpp}. Users of these macros (if any) should start replacing them 
+      with more up to date code, such as using attributes or modules. 
+    }
   }
 }
 

Modified: pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h	2013-06-18 17:08:35 UTC (rev 4342)
+++ pkg/Rcpp/inst/include/Rcpp/vector/string_proxy.h	2013-06-19 13:03:50 UTC (rev 4343)
@@ -182,7 +182,18 @@
 		bool operator==( const char* other){
 			return strcmp( begin(), other ) == 0 ;
 		}
-			
+		bool operator!=( const char* other){
+			return strcmp( begin(), other ) != 0 ;
+		}
+		
+		bool operator==( const string_proxy& other){
+			return strcmp( begin(), other.begin() ) == 0 ;
+		}
+		bool operator!=( const string_proxy& other){
+			return strcmp( begin(), other.begin() ) != 0 ;
+		}
+		
+		
 		private:
 			static std::string buffer ;
 		

Modified: pkg/Rcpp/inst/unitTests/cpp/Vector.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/Vector.cpp	2013-06-18 17:08:35 UTC (rev 4342)
+++ pkg/Rcpp/inst/unitTests/cpp/Vector.cpp	2013-06-19 13:03:50 UTC (rev 4343)
@@ -665,6 +665,17 @@
     return l.containsElementNamed(n[0]);
 }
 
+// [[Rcpp::export]]
+List CharacterVectorEqualityOperator( CharacterVector x, CharacterVector y){
+    int n = x.size() ;
+    LogicalVector eq(n), neq(n);
+    for( int i=0; i<n; i++){
+        eq[i]  = x[i] == y[i] ;
+        neq[i] = x[i] != y[i] ; 
+    }
+    return List::create(eq, neq) ;
+}
+
 #if defined(HAS_INIT_LISTS)
     RawVector raw_initializer_list(){
         RawVector x = {0,1,2,3} ;

Modified: pkg/Rcpp/inst/unitTests/runit.Vector.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Vector.R	2013-06-18 17:08:35 UTC (rev 4342)
+++ pkg/Rcpp/inst/unitTests/runit.Vector.R	2013-06-19 13:03:50 UTC (rev 4343)
@@ -590,6 +590,13 @@
     checkEquals(fun(x, ""), FALSE, msg = "containsElementNamed with empty element")
 }
 
+test.CharacterVector.equality.operator <- function(){
+    res <- CharacterVectorEqualityOperator( letters, letters )
+    checkEquals( res, 
+        list( rep( TRUE, 26L ), rep( FALSE, 26L) ), 
+        msg = 'CharacterVector element equality operator' )    
+}
+
 # test graveyard. Might come back when we can use C++11
 
 # if( Rcpp:::capabilities()[["initializer lists"]] ){



More information about the Rcpp-commits mailing list