[Rcpp-commits] r3557 - in pkg/Rcpp: . inst/include/Rcpp/vector

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 29 19:09:30 CEST 2012


Author: romain
Date: 2012-03-29 19:09:29 +0200 (Thu, 29 Mar 2012)
New Revision: 3557

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
Log:
new Vector<>::has_element_called method

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-03-28 22:28:45 UTC (rev 3556)
+++ pkg/Rcpp/ChangeLog	2012-03-29 17:09:29 UTC (rev 3557)
@@ -1,3 +1,7 @@
+2012-03-29  Romain Francois  <romain at r-enthusiasts.com>
+
+    * inst/include/Rcpp/vector/Vector.h: Vector<> gains the has_element_called method
+
 2012-03-24  Romain Francois  <romain at r-enthusiasts.com>
 
 	* src/cache.cpp: Using a single Rcpp_cache, stored in the Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2012-03-28 22:28:45 UTC (rev 3556)
+++ pkg/Rcpp/inst/include/Rcpp/vector/Vector.h	2012-03-29 17:09:29 UTC (rev 3557)
@@ -703,6 +703,20 @@
         return *this ;
     }
     
+    /** 
+     *  Does this vector have an element with the target name 
+     */
+    bool has_element_called( const char* target ) const {
+        SEXP names = RCPP_GET_NAMES(m_sexp) ; 
+        if( Rf_isNull(names) ) return false ;
+        int n = Rf_length(names) ;
+        for( int i=0; i<n; i++){
+            if( !strcmp( target, CHAR(STRING_ELT(names, i)) ) ) return true ;   
+        }
+        return false ;
+    }
+    
+    
 } ; /* Vector */
 
 template <int RTYPE>



More information about the Rcpp-commits mailing list