[Rcpp-commits] r4302 - in pkg/Rcpp: . inst inst/include/Rcpp inst/unitTests inst/unitTests/cpp src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 3 05:08:06 CEST 2013


Author: edd
Date: 2013-04-03 05:08:06 +0200 (Wed, 03 Apr 2013)
New Revision: 4302

Added:
   pkg/Rcpp/inst/unitTests/cpp/dates.cpp
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/inst/include/Rcpp/Date.h
   pkg/Rcpp/inst/unitTests/runit.Date.R
   pkg/Rcpp/src/Date.cpp
Log:
correct operator-() for Date and Datetime
update unit tests accordingly
rewritten unit test to use Rcpp attributes


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-04-02 18:24:00 UTC (rev 4301)
+++ pkg/Rcpp/ChangeLog	2013-04-03 03:08:06 UTC (rev 4302)
@@ -1,14 +1,25 @@
+2013-04-02  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/Date.cpp (Rcpp): Corrected operator-() for Date and Datetime
+	objects to do what is more inline with C++ standard
+
+	* inst/include/Rcpp/Date.h: operator-() for Dates now returns a
+	double as the date itself is fractional double since epoch
+
+	* inst/unitTests/cpp/dates.cpp: New file with C++ portion of tests
+	factored out from R unit test file
+	* inst/unitTests/runit.Date.R: Rewritten for use with new C++ tests
+
 2013-04-02 Romain Francois <romain at r-enthusiasts.com>
 
         * include/Rcpp/generated/DataFrame_generated.h : DateFrame::create
-        uses List::create and then feeds to the DataFrame constructor, which 
-        seems to work better than the previous approach of calling back to the 
+        uses List::create and then feeds to the DataFrame constructor, which
+        seems to work better than the previous approach of calling back to the
         data.frame function in R
-        * include/Rcpp/DataFrame.h : private function from_list, to help 
+        * include/Rcpp/DataFrame.h : private function from_list, to help
         the new implementation of DataFrame::create
         * src/api.cpp : impl of DataFrame::from_list
-        
-        
+
 2013-03-31  Dirk Eddelbuettel  <edd at debian.org>
 
 	* debian/control (Build-Depends): Modified for Debian-only rebuilds

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2013-04-02 18:24:00 UTC (rev 4301)
+++ pkg/Rcpp/inst/NEWS.Rd	2013-04-03 03:08:06 UTC (rev 4302)
@@ -8,11 +8,12 @@
     \item Changes in Rcpp attributes: 
     \item Changes in Rcpp API:
     \itemize{
-        \item The \code{DataFrame::create} set of functions has been reworked
-        to just use \code{List::create} and feed to the \code{DataFrame}
-        constructor
+      \item The \code{DataFrame::create} set of functions has been reworked
+      to just use \code{List::create} and feed to the \code{DataFrame}
+      constructor
+      \item The \code{operator-()} semantics for \code{Date} and
+      \code{Datetime} are now more inline with standard C++ behaviour.
     }
-  }
 }
 
 \section{Changes in Rcpp version 0.10.3 (2013-03-23)}{

Modified: pkg/Rcpp/inst/include/Rcpp/Date.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Date.h	2013-04-02 18:24:00 UTC (rev 4301)
+++ pkg/Rcpp/inst/include/Rcpp/Date.h	2013-04-03 03:08:06 UTC (rev 4302)
@@ -2,7 +2,7 @@
 //
 // Date.h: Rcpp R/C++ interface class library -- dates
 //
-// Copyright (C) 2010 - 2012  Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2013  Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -55,14 +55,14 @@
 		Date & operator=(const Date &newdate); 					// copy assignment operator 
 
 		// Minimal set of date operations.
-		friend Date  operator+(const Date &date, int offset);
-		friend int   operator-(const Date& date1, const Date& date2);
-		friend bool  operator<(const Date &date1, const Date& date2);
-		friend bool  operator>(const Date &date1, const Date& date2);
-		friend bool  operator==(const Date &date1, const Date& date2);
-		friend bool  operator>=(const Date &date1, const Date& date2);
-		friend bool  operator<=(const Date &date1, const Date& date2);
-		friend bool  operator!=(const Date &date1, const Date& date2);
+		friend Date   operator+(const Date &date, int offset);
+		friend double operator-(const Date& date1, const Date& date2);
+		friend bool   operator<(const Date &date1, const Date& date2);
+		friend bool   operator>(const Date &date1, const Date& date2);
+		friend bool   operator==(const Date &date1, const Date& date2);
+		friend bool   operator>=(const Date &date1, const Date& date2);
+		friend bool   operator<=(const Date &date1, const Date& date2);
+		friend bool   operator!=(const Date &date1, const Date& date2);
 
     private:
         double m_d;					// (fractional) day number, relative to epoch of Jan 1, 1970

Added: pkg/Rcpp/inst/unitTests/cpp/dates.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/dates.cpp	                        (rev 0)
+++ pkg/Rcpp/inst/unitTests/cpp/dates.cpp	2013-04-03 03:08:06 UTC (rev 4302)
@@ -0,0 +1,160 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+//
+// dates.cpp: Rcpp R/C++ interface class library -- Date + Datetime tests
+//
+// Copyright (C) 2010 - 2013   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/>.
+
+#include <Rcpp.h>
+using namespace Rcpp;
+
+// [[Rcpp::export]]
+Date ctor_sexp(SEXP d) {
+    Date dt = Date(d);
+    return dt;
+}
+
+// [[Rcpp::export]]
+SEXP ctor_mdy(int ignoreme) {
+    Date dt = Date(12,31,2005);
+    return wrap(dt);
+}
+
+// [[Rcpp::export]]
+SEXP ctor_ymd(int ignoreme) {
+    Date dt = Date(2005,12,31);
+    return wrap(dt);
+}
+
+// [[Rcpp::export]]
+SEXP ctor_int(int d) {
+    Date dt = Date(d);
+    return wrap(dt);
+}
+
+// [[Rcpp::export]]
+SEXP ctor_string(std::string x) {
+    Date dt(x);
+    return wrap(dt);
+}
+
+// [[Rcpp::export]]
+List operators(int ignoreme) {
+    Date d1 = Date(2005,12,31);
+    Date d2 = d1 + 1;
+    return List::create(Named("diff") = d1 - d2,
+                        Named("bigger") = d2 > d1,
+                        Named("smaller") = d2 < d1,
+                        Named("equal") = d2 == d1,
+                        Named("ge") = d2 >= d1,
+                        Named("le") = d2 <= d1,
+                        Named("ne") = d2 != d1);
+}
+
+// [[Rcpp::export]]
+List components(int ignoreme) {
+    Date d = Date(2005,12,31);
+    return List::create(Named("day") = d.getDay(),
+                        Named("month") = d.getMonth(),
+                        Named("year") = d.getYear(),
+                        Named("weekday") = d.getWeekday(),
+                        Named("yearday") = d.getYearday());
+}
+
+// [[Rcpp::export]]
+SEXP vector_Date(int ignoreme) {
+    std::vector<Date> v(2) ;
+    v[0] = Date(2005,12,31) ;
+    v[1] = Date(12,31,2005) ;
+    return wrap( v );
+}
+
+// [[Rcpp::export]]
+SEXP Datevector_wrap(int ignoreme) {
+    DateVector v(2) ;
+    v[0] = Date(2005,12,31) ;
+    v[1] = Date(12,31,2005) ;
+    return wrap( v );
+}
+
+// [[Rcpp::export]]
+SEXP Datevector_sexp(int ignoreme) {
+    DateVector v(2) ;
+    v[0] = Date(2005,12,31) ;
+    v[1] = Date(12,31,2005) ;
+    return wrap( v );
+}
+
+// [[Rcpp::export]]
+List Date_get_functions(Date x) {
+    Date d = Date(x);
+    return List::create(Named("year") = d.getYear(),
+                        Named("month") = d.getMonth(),
+                        Named("day") = d.getDay(),
+                        Named("wday") = d.getWeekday(),
+                        Named("yday") = d.getYearday());
+}
+
+// [[Rcpp::export]]
+List Datetime_get_functions(Datetime x) {
+    Datetime dt = Datetime(x);
+    return List::create(Named("year") = dt.getYear(),
+                        Named("month") = dt.getMonth(),
+                        Named("day") = dt.getDay(),
+                        Named("wday") = dt.getWeekday(),
+                        Named("hour") = dt.getHours(),
+                        Named("minute") = dt.getMinutes(),
+                        Named("second") = dt.getSeconds(),
+                        Named("microsec") = dt.getMicroSeconds());
+}
+
+// [[Rcpp::export]]
+List Datetime_operators(int ignoreme) {
+    Datetime d1 = Datetime(946774923.123456);
+    Datetime d2 = d1 + 60*60;
+    return List::create(Named("diff") = d1 - d2,
+                        Named("bigger") = d2 > d1,
+                        Named("smaller") = d2 < d1,
+                        Named("equal") = d2 == d1,
+                        Named("ge") = d2 >= d1,
+                        Named("le") = d2 <= d1,
+                        Named("ne") = d2 != d1);
+}
+
+// [[Rcpp::export]]
+SEXP Datetime_wrap(int ignoreme) {
+    Datetime dt = Datetime(981162123.123456);
+    return wrap(dt);
+}
+
+// [[Rcpp::export]]
+SEXP Datetime_from_string(std::string x) {
+    Datetime dt(x);
+    return wrap(dt);
+}
+
+// [[Rcpp::export]]
+SEXP Datetime_ctor_sexp(Datetime d) {
+    Datetime dt = Datetime(d);
+    return wrap(dt);
+}
+
+// [[Rcpp::export]]
+SEXP DatetimeVector_ctor(DatetimeVector d) {
+    DatetimeVector dt = DatetimeVector(d);
+    return wrap(dt);
+}

Modified: pkg/Rcpp/inst/unitTests/runit.Date.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Date.R	2013-04-02 18:24:00 UTC (rev 4301)
+++ pkg/Rcpp/inst/unitTests/runit.Date.R	2013-04-03 03:08:06 UTC (rev 4302)
@@ -1,7 +1,7 @@
 #!/usr/bin/r -t
 # -*- mode: R; tab-width: 4; -*-
 #
-# Copyright (C) 2010 - 2012   Dirk Eddelbuettel and Romain Francois
+# Copyright (C) 2010 - 2013   Dirk Eddelbuettel and Romain Francois
 #
 # This file is part of Rcpp.
 #
@@ -22,143 +22,13 @@
 
 if (.runThisTest) {
 
-definitions <- function() {
-    list(          "ctor_sexp"=list(
-                   signature(d="Date"),
-                   'Date dt = Date(d);
-                   return wrap(dt);')
-
-                  ,"ctor_mdy"=list(
-                   signature(),
-                   'Date dt = Date(12,31,2005);
-                   return wrap(dt);')
-
-                  ,"ctor_ymd"=list(
-                   signature(),
-                   'Date dt = Date(2005,12,31);
-                    return wrap(dt);')
-
-                  ,"ctor_int"=list(
-                   signature(d="numeric"),
-                   'Date dt = Date(Rcpp::as<int>(d));
-                    return wrap(dt);')
-
-                  ,"ctor_string"=list(
-                   signature(x="date"),
-                   'std::string dtstr = Rcpp::as<std::string>(x);
-                    Date dt(dtstr);
-				    return wrap(dt);')
-
-                   ,"operators"=list(
-                    signature(),
-                    'Date d1 = Date(2005,12,31);
-                    Date d2 = d1 + 1;
-                    return List::create(Named("diff") = d2 - d1,
-                                        Named("bigger") = d2 > d1,
-                                        Named("smaller") = d2 < d1,
-                                        Named("equal") = d2 == d1,
-                                        Named("ge") = d2 >= d1,
-                                        Named("le") = d2 <= d1,
-                                        Named("ne") = d2 != d1);')
-
-                  ,"components"=list(
-                   signature(),
-                   'Date d = Date(2005,12,31);
-                    return List::create(Named("day") = d.getDay(),
-                                        Named("month") = d.getMonth(),
-                                        Named("year") = d.getYear(),
-                                        Named("weekday") = d.getWeekday(),
-                                        Named("yearday") = d.getYearday());')
-
-                  ,"vector_Date"=list(
-                   signature(),
-                   'std::vector<Date> v(2) ;
-                    v[0] = Date(2005,12,31) ;
-                    v[1] = Date(12,31,2005) ;
-                    return wrap( v );')
-
-                  ,"Datevector_wrap"=list(
-                   signature(),
-                   'DateVector v(2) ;
-                    v[0] = Date(2005,12,31) ;
-                    v[1] = Date(12,31,2005) ;
-                    return wrap( v );')
-
-                  ,"Datevector_sexp"=list(
-                   signature(),
-                   'DateVector v(2) ;
-                    v[0] = Date(2005,12,31) ;
-                    v[1] = Date(12,31,2005) ;
-                    return wrap( v );')
-
-                  ,"Date_get_functions"=list(
-                   signature(x="Date"),
-                   'Date d = Date(x);
-		            return List::create(Named("year") = d.getYear(),
-    		                            Named("month") = d.getMonth(),
-    		                            Named("day") = d.getDay(),
-    		                            Named("wday") = d.getWeekday(),
-    		                            Named("yday") = d.getYearday());')
-
-                  ,"Datetime_get_functions"=list(
-                   signature(x="Datetime"),
-                   'Datetime dt = Datetime(x);
-		            return List::create(Named("year") = dt.getYear(),
-    		                            Named("month") = dt.getMonth(),
-    		                            Named("day") = dt.getDay(),
-    		                            Named("wday") = dt.getWeekday(),
-    		                            Named("hour") = dt.getHours(),
-    		                            Named("minute") = dt.getMinutes(),
-    		                            Named("second") = dt.getSeconds(),
-    		                            Named("microsec") = dt.getMicroSeconds());')
-
-                  ,"Datetime_operators"=list(
-                   signature(),
-                   'Datetime d1 = Datetime(946774923.123456);
-		            Datetime d2 = d1 + 60*60;
-		            return List::create(Named("diff") = d2 - d1,
-		                                Named("bigger") = d2 > d1,
-		                                Named("smaller") = d2 < d1,
-		                                Named("equal") = d2 == d1,
-		                                Named("ge") = d2 >= d1,
-		                                Named("le") = d2 <= d1,
-		                                Named("ne") = d2 != d1);')
-
-                  ,"Datetime_wrap"=list(
-                   signature(),
-                   'Datetime dt = Datetime(981162123.123456);
-				    return wrap(dt);')
-
-                  ,"Datetime_from_string"=list(
-                   signature(x="datetime"),
-                   'std::string dtstr = Rcpp::as<std::string>(x);
-                    Datetime dt(dtstr);
-				    return wrap(dt);')
-
-                  ,"Datetime_ctor_sexp"=list(
-                   signature(d="Datetime"),
-                   'Datetime dt = Datetime(d);
-                   return wrap(dt);')
-
-                  ,"DatetimeVector_ctor"=list(
-                   signature(d="DatetimeVector"),
-                   'DatetimeVector dt = DatetimeVector(d);
-                   return wrap(dt);')
-
-                  )
+.setUp <- function(){
+    if (!exists("pathRcppTests")) pathRcppTests <- getwd()
+    sourceCpp(file.path(pathRcppTests, "cpp/dates.cpp"))
 }
 
-.setUp <- function() {
-    tests <- ".Rcpp.Date"
-    if( ! exists(tests, globalenv() )) {
-        fun <- Rcpp:::compile_unit_tests(definitions() )
-        assign( tests, fun , globalenv() )
-    }
-}
-
-
 test.Date.ctor.sexp <- function() {
-    fun <- .Rcpp.Date$ctor_sexp
+    fun <- ctor_sexp
     d <- as.Date("2005-12-31"); checkEquals(fun(d), d, msg = "Date.ctor.sexp.1")
     d <- as.Date("1970-01-01"); checkEquals(fun(d), d, msg = "Date.ctor.sexp.2")
     d <- as.Date("1969-12-31"); checkEquals(fun(d), d, msg = "Date.ctor.sexp.3")
@@ -167,14 +37,14 @@
 }
 
 test.Date.ctor.notFinite <- function() {
-    fun <- .Rcpp.Date$ctor_sexp
+    fun <- ctor_sexp
     checkEquals(fun(NA),  as.Date(NA,  origin="1970-01-01"), msg = "Date.ctor.na")
     checkEquals(fun(NaN), as.Date(NaN, origin="1970-01-01"), msg = "Date.ctor.nan")
     checkEquals(fun(Inf), as.Date(Inf, origin="1970-01-01"), msg = "Date.ctor.inf")
 }
 
 test.Date.ctor.diffs <- function() {
-    fun <- .Rcpp.Date$ctor_sexp
+    fun <- ctor_sexp
     now <- Sys.Date()
     checkEquals(as.numeric(difftime(fun(now+0.025),  fun(now), units="days")), 0.025, msg = "Date.ctor.diff.0025")
     checkEquals(as.numeric(difftime(fun(now+0.250),  fun(now), units="days")), 0.250, msg = "Date.ctor.diff.0250")
@@ -182,17 +52,17 @@
 }
 
 test.Date.ctor.mdy <- function() {
-    fun <- .Rcpp.Date$ctor_mdy
-    checkEquals(fun(), as.Date("2005-12-31"), msg = "Date.ctor.mdy")
+    fun <- ctor_mdy
+    checkEquals(fun(1), as.Date("2005-12-31"), msg = "Date.ctor.mdy")
 }
 
 test.Date.ctor.ymd <- function() {
-    fun <- .Rcpp.Date$ctor_ymd
-    checkEquals(fun(), as.Date("2005-12-31"), msg = "Date.ctor.ymd")
+    fun <- ctor_ymd
+    checkEquals(fun(1), as.Date("2005-12-31"), msg = "Date.ctor.ymd")
 }
 
 test.Date.ctor.int <- function() {
-    fun <- .Rcpp.Date$ctor_int
+    fun <- ctor_int
     d <- as.Date("2005-12-31")
     checkEquals(fun(as.numeric(d)), d, msg = "Date.ctor.int")
     checkEquals(fun(-1), as.Date("1970-01-01")-1, msg = "Date.ctor.int")
@@ -200,7 +70,7 @@
 }
 
 test.Date.ctor.string <- function() {
-    fun <- .Rcpp.Date$ctor_string
+    fun <- ctor_string
     dtstr <- "1991-02-03"
     dtfun <- fun(dtstr)
     dtstr <- as.Date(strptime(dtstr, "%Y-%m-%d"))
@@ -210,36 +80,36 @@
 }
 
 test.Date.operators <- function() {
-    fun <- .Rcpp.Date$operators
-    checkEquals(fun(),
+    fun <- operators
+    checkEquals(fun(1),
                 list(diff=-1, bigger=TRUE, smaller=FALSE, equal=FALSE, ge=TRUE, le=FALSE, ne=TRUE),
                 msg = "Date.operators")
 }
 
 test.Date.components <- function() {
-    fun <- .Rcpp.Date$components
-    checkEquals(fun(),
+    fun <- components
+    checkEquals(fun(1),
                 list(day=31, month=12, year=2005, weekday=7, yearday=365),
                 msg = "Date.components")
 }
 
 test.vector.Date <- function(){
-    fun <- .Rcpp.Date$vector_Date
-    checkEquals(fun(), rep(as.Date("2005-12-31"),2), msg = "Date.vector.wrap")
+    fun <- vector_Date
+    checkEquals(fun(1), rep(as.Date("2005-12-31"),2), msg = "Date.vector.wrap")
 }
 
 test.DateVector.wrap <- function(){
-    fun <- .Rcpp.Date$Datevector_wrap
-    checkEquals(fun(), rep(as.Date("2005-12-31"),2), msg = "DateVector.wrap")
+    fun <- Datevector_wrap
+    checkEquals(fun(1), rep(as.Date("2005-12-31"),2), msg = "DateVector.wrap")
 }
 
 test.DateVector.operator.SEXP <- function(){
-    fun <- .Rcpp.Date$Datevector_sexp
-    checkEquals(fun(), rep(as.Date("2005-12-31"),2), msg = "DateVector.SEXP")
+    fun <- Datevector_sexp
+    checkEquals(fun(1), rep(as.Date("2005-12-31"),2), msg = "DateVector.SEXP")
 }
 
 test.Date.getFunctions <- function(){
-    fun <- .Rcpp.Date$Date_get_functions
+    fun <- Date_get_functions
     checkEquals(fun(as.Date("2010-12-04")),
                 list(year=2010, month=12, day=4, wday=7, yday=338), msg = "Date.get.functions.1")
     checkEquals(fun(as.Date("2010-01-01")),
@@ -249,27 +119,27 @@
 }
 
 test.Datetime.get.functions <- function() {
-    fun <- .Rcpp.Date$Datetime_get_functions
+    fun <- Datetime_get_functions
     checkEquals(fun(as.numeric(as.POSIXct("2001-02-03 01:02:03.123456", tz="UTC"))),
                 list(year=2001, month=2, day=3, wday=7, hour=1, minute=2, second=3, microsec=123456),
                 msg = "Datetime.get.functions")
 }
 
 test.Datetime.operators <- function() {
-    fun <- .Rcpp.Date$Datetime_operators
-    checkEquals(fun(),
+    fun <- Datetime_operators
+    checkEquals(fun(1),
                 list(diff=-60*60, bigger=TRUE, smaller=FALSE, equal=FALSE, ge=TRUE, le=FALSE, ne=TRUE),
                 msg = "Datetime.operators")
 }
 
 test.Datetime.wrap <- function() {
-    fun <- .Rcpp.Date$Datetime_wrap
-    checkEquals(as.numeric(fun()), as.numeric(as.POSIXct("2001-02-03 01:02:03.123456", tz="UTC")),
+    fun <- Datetime_wrap
+    checkEquals(as.numeric(fun(1)), as.numeric(as.POSIXct("2001-02-03 01:02:03.123456", tz="UTC")),
                 msg = "Datetime.wrap")
 }
 
 test.Datetime.fromString <- function() {
-    fun <- .Rcpp.Date$Datetime_from_string
+    fun <- Datetime_from_string
     dtstr <- "1991-02-03 04:05:06.789"
     dtfun <- fun(dtstr)
     dtstr <- as.POSIXct(strptime(dtstr, "%Y-%m-%d %H:%M:%OS"))
@@ -285,7 +155,7 @@
 #}
 
 test.Datetime.ctor.notFinite <- function() {
-    fun <- .Rcpp.Date$Datetime_ctor_sexp
+    fun <- Datetime_ctor_sexp
     posixtNA <- as.POSIXct(NA,  origin="1970-01-01")
     checkEquals(fun(NA),  posixtNA, msg = "Datetime.ctor.na")
     checkEquals(fun(NaN), posixtNA, msg = "Datetime.ctor.nan")
@@ -293,7 +163,7 @@
 }
 
 test.Datetime.ctor.diffs <- function() {
-    fun <- .Rcpp.Date$Datetime_ctor_sexp
+    fun <- Datetime_ctor_sexp
     now <- Sys.time()
     ## first one is Ripley's fault as he decreed that difftime of POSIXct should stop at milliseconds
     checkEquals(round(as.numeric(difftime(fun(now+0.025),  fun(now), units="sec")), digits=4), 0.025, msg = "Datetime.ctor.diff.0025")
@@ -302,7 +172,7 @@
 }
 
 test.DatetimeVector.ctor <- function() {
-    fun <- .Rcpp.Date$DatetimeVector_ctor
+    fun <- DatetimeVector_ctor
     now <- Sys.time()
     checkEquals(fun(now + (0:4)*60), now+(0:4)*60, msg = "Datetime.ctor.sequence")
     vec <- c(now, NA, NaN, Inf, now+2.345)

Modified: pkg/Rcpp/src/Date.cpp
===================================================================
--- pkg/Rcpp/src/Date.cpp	2013-04-02 18:24:00 UTC (rev 4301)
+++ pkg/Rcpp/src/Date.cpp	2013-04-03 03:08:06 UTC (rev 4302)
@@ -3,7 +3,7 @@
 //
 // Date.cpp: Rcpp R/C++ interface class library -- Date type
 //
-// Copyright (C) 2010 - 2012  Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2013  Dirk Eddelbuettel and Romain Francois
 //
 //    The mktime00() as well as the gmtime_() replacement function are
 //    Copyright (C) 2000 - 2010  The R Development Core Team.
@@ -167,7 +167,14 @@
 	return newdate;
     }
 
-    int   operator-(const Date& d1, const Date& d2) { return d2.m_d - d1.m_d; }
+    // int operator-(const Date& d1, const Date& d2) { return d2.m_d - d1.m_d; }
+    double operator-(const Date& d1, const Date& d2) {
+        //Rprintf( "d1 = %lf\n", d1.m_d ) ;
+        //Rprintf( "d2 = %lf\n", d2.m_d ) ;
+        double diff =  d1.m_d - d2.m_d;
+        //Rprintf( "diff = %lf\n", diff );
+        return diff ;
+    }
     bool  operator<(const Date &d1, const Date& d2) { return d1.m_d < d2.m_d; }
     bool  operator>(const Date &d1, const Date& d2) { return d1.m_d > d2.m_d; }
     bool  operator==(const Date &d1, const Date& d2) { return d1.m_d == d2.m_d; }
@@ -267,7 +274,7 @@
 		return newdt;
     }
 
-    double  operator-(const Datetime& d1, const Datetime& d2) { return d2.m_dt - d1.m_dt; }
+    double  operator-(const Datetime& d1, const Datetime& d2) { return d1.m_dt - d2.m_dt; }
     bool    operator<(const Datetime &d1, const Datetime& d2) { return d1.m_dt < d2.m_dt; }
     bool    operator>(const Datetime &d1, const Datetime& d2) { return d1.m_dt > d2.m_dt; }
     bool    operator==(const Datetime &d1, const Datetime& d2) { return d1.m_dt == d2.m_dt; }



More information about the Rcpp-commits mailing list