[Rcpp-commits] r4405 - in pkg/Rcpp: . inst inst/include/Rcpp inst/include/Rcpp/sugar/functions

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 25 10:15:35 CEST 2013


Author: romain
Date: 2013-07-25 10:15:34 +0200 (Thu, 25 Jul 2013)
New Revision: 4405

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/inst/include/Rcpp/Date.h
   pkg/Rcpp/inst/include/Rcpp/Datetime.h
   pkg/Rcpp/inst/include/Rcpp/sugar/functions/is_na.h
Log:
added is_na impl for DateVector and DatetimeVector

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-07-24 16:18:55 UTC (rev 4404)
+++ pkg/Rcpp/ChangeLog	2013-07-25 08:15:34 UTC (rev 4405)
@@ -1,3 +1,10 @@
+2013-07-25 Romain Francois <romain at r-enthusiasts.com>
+
+        * include/Rcpp/sugar/functions/is_na.h : added is_na for DateVector and
+        DatetimeVector
+        * include/Rcpp/Date.h : added is_na method
+        * include/Rcpp/Datetime.h : added is_na method
+        
 2013-07-24  Romain Francois <romain at r-enthusiasts.com>
 
         * include/Rcpp/traits/is_module_object.h: trait class that identifies

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2013-07-24 16:18:55 UTC (rev 4404)
+++ pkg/Rcpp/inst/NEWS.Rd	2013-07-25 08:15:34 UTC (rev 4405)
@@ -42,6 +42,12 @@
       objects are no longer copied as they used to be. 
     }
 
+    \item Changes in sugar:
+    \itemize{
+        \item \code{is_na} supports classes \code{DatetimeVector} and 
+        \code{DateVector}
+    }
+    
     \item Deprecation of \code{RCPP_FUNCTION_*}:
     \itemize{
       \item The macros from the \code{preprocessor_generated.h} file

Modified: pkg/Rcpp/inst/include/Rcpp/Date.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Date.h	2013-07-24 16:18:55 UTC (rev 4404)
+++ pkg/Rcpp/inst/include/Rcpp/Date.h	2013-07-25 08:15:34 UTC (rev 4405)
@@ -64,6 +64,8 @@
 		friend bool   operator<=(const Date &date1, const Date& date2);
 		friend bool   operator!=(const Date &date1, const Date& date2);
 
+		inline int is_na() const { return traits::is_na<REALSXP>( m_d ) ; }
+		
     private:
         double m_d;					// (fractional) day number, relative to epoch of Jan 1, 1970
         struct tm m_tm;				// standard time representation

Modified: pkg/Rcpp/inst/include/Rcpp/Datetime.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Datetime.h	2013-07-24 16:18:55 UTC (rev 4404)
+++ pkg/Rcpp/inst/include/Rcpp/Datetime.h	2013-07-25 08:15:34 UTC (rev 4405)
@@ -2,7 +2,7 @@
 //
 // Datetime.h: Rcpp R/C++ interface class library -- Datetime (POSIXct)
 //
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -59,13 +59,15 @@
 		friend bool      operator<=(const Datetime &dt1, const Datetime& dt2);
 		friend bool      operator!=(const Datetime &dt1, const Datetime& dt2);
 
+		inline int is_na() const { return traits::is_na<REALSXP>( m_dt ) ; }
+		
     private:
         double m_dt;				// fractional seconds since epoch
-        struct tm m_tm;				// standard time representation
-		unsigned int m_us;			// microsecond (to complement m_tm)
+        struct tm m_tm;			// standard time representation
+        unsigned int m_us;		// microsecond (to complement m_tm)
+                                
+        void update_tm();		// update m_tm based on m_dt
 
-		void update_tm();			// update m_tm based on m_dt
-
     };
 
 

Modified: pkg/Rcpp/inst/include/Rcpp/sugar/functions/is_na.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/sugar/functions/is_na.h	2013-07-24 16:18:55 UTC (rev 4404)
+++ pkg/Rcpp/inst/include/Rcpp/sugar/functions/is_na.h	2013-07-25 08:15:34 UTC (rev 4405)
@@ -66,7 +66,21 @@
 	
 } ;
 
-	
+template <typename T>
+class IsNa_Vector_is_na : public Rcpp::VectorBase<LGLSXP, false, IsNa_Vector_is_na<T> >{
+   public:
+       IsNa_Vector_is_na( const T& x) : ref(x){}
+       
+       inline int operator[]( int i) const {
+           return ref[i].is_na() ;
+       }
+       
+       inline int size() const { return ref.size() ; } 
+       
+   private:
+        const T& ref ;       
+} ;
+
 } // sugar
 
 template <int RTYPE, bool NA, typename T>
@@ -74,6 +88,13 @@
 	return sugar::IsNa<RTYPE,NA,T>( t ) ;
 }
 
+inline sugar::IsNa_Vector_is_na<DatetimeVector> is_na( const DatetimeVector& x){
+    return sugar::IsNa_Vector_is_na<DatetimeVector>( x ) ;
+}
+inline sugar::IsNa_Vector_is_na<DateVector> is_na( const DateVector& x){
+    return sugar::IsNa_Vector_is_na<DateVector>( x ) ;
+}
+
 } // Rcpp
 #endif
 



More information about the Rcpp-commits mailing list