[Rcpp-commits] r3878 - in pkg/RcppBDT: . R inst/include src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 1 03:42:30 CET 2012


Author: edd
Date: 2012-11-01 03:42:28 +0100 (Thu, 01 Nov 2012)
New Revision: 3878

Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/DESCRIPTION
   pkg/RcppBDT/R/bdt.R
   pkg/RcppBDT/R/zzz.R
   pkg/RcppBDT/inst/include/RcppBDT.h
   pkg/RcppBDT/inst/include/RcppBDTdd.h
   pkg/RcppBDT/inst/include/RcppBDTdt.h
   pkg/RcppBDT/src/RcppBDTdd.cpp
   pkg/RcppBDT/src/RcppBDTdt.cpp
Log:
a few small-ish updates adding bits of functionality


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/ChangeLog	2012-11-01 02:42:28 UTC (rev 3878)
@@ -1,5 +1,15 @@
-2012-10-26  Dirk Eddelbuettel  <edd at dexter>
+2012-10-31  Dirk Eddelbuettel  <edd at debian.org>
 
+	* R/bdt.R: switch from fromDate() to setDate()
+
+	* inst/include/RcppBDTdt.h: addMonth(), addYears() added which can't
+	be done via date_duration as they need a date for context
+	* src/RcppBDTdt.cpp: idem 
+
+	* src/RcppBDTdd.cpp: added weeks()
+
+2012-10-26  Dirk Eddelbuettel  <edd at debian.org>
+
 	* inst/include/RcppBDTdd.h: New class date_duration
 	* src/RcppBDTdd.cpp: Implementation
 	* R/zzz.R: Dispatching new methods for new class
@@ -101,7 +111,7 @@
 	can represents hours, minutes, seconds, down to milli, micro and
 	nanoseconds (where the last part may be OS-dependent, see Boost docs)
 
-2012-08-24  Dirk Eddelbuettel  <edd at dexter>
+2012-08-24  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/RcppBDTtz.cpp: Use Language evaluation to get location of zone
 	db file, reducing constructor to single argument for region; also
@@ -109,13 +119,13 @@
 
 	* R/zzz.R: add default display methods for bdtTz objects
 
-2012-08-22  Dirk Eddelbuettel  <edd at dexter>
+2012-08-22  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/RcppBDTtz.cpp: Rewrote bdtTz to be based on small class
 	wrapping tz_db object plus one pointer both of which are initialized
 	from the constructor
 
-2012-08-20  Dirk Eddelbuettel  <edd at dexter>
+2012-08-20  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/RcppBDTtz.cpp: New module 'bdtTz' for time zone functionality
 	* R/zzz.R: Load bdtTzMod module on startup

Modified: pkg/RcppBDT/DESCRIPTION
===================================================================
--- pkg/RcppBDT/DESCRIPTION	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/DESCRIPTION	2012-11-01 02:42:28 UTC (rev 3878)
@@ -16,5 +16,5 @@
 LazyLoad: yes
 Depends: Rcpp (>= 0.9.15.3), methods
 Imports: methods, Rcpp
-LinkingTo: Rcpp, BoostHeaders
+LinkingTo: Rcpp
 SystemRequirements: Boost (or the BoostHeaders package)

Modified: pkg/RcppBDT/R/bdt.R
===================================================================
--- pkg/RcppBDT/R/bdt.R	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/R/bdt.R	2012-11-01 02:42:28 UTC (rev 3878)
@@ -20,43 +20,43 @@
 
 getEndOfBizWeek <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdt$fromDate(date)
-    bdt$getEndOfBizWeek(date)
+    bdt$setDate(date)
+    bdt$getEndOfBizWeek()
 }
 
 getEndOfMonth <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdt$fromDate(date)
-    bdt$getEndOfMonth(date)
+    bdt$setDate(date)
+    bdt$getEndOfMonth()
 }
 
 getYear <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdt$fromDate(date)
+    bdt$setDate(date)
     bdt$getYear()
 }
 
 getMonth <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdt$fromDate(date)
+    bdt$setDate(date)
     bdt$getMonth()
 }
 
 getDay <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdt$fromDate(date)
+    bdt$setDate(date)
     bdt$getDay()
 }
 
 getDayOfWeek <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdt$fromDate(date)
+    bdt$setDate(date)
     bdt$getDayOfWeek()
 }
 
 getDayOfYear <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdt$fromDate(date)
+    bdt$setDate(date)
     bdt$getDayOfYear()
 }
 

Modified: pkg/RcppBDT/R/zzz.R
===================================================================
--- pkg/RcppBDT/R/zzz.R	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/R/zzz.R	2012-11-01 02:42:28 UTC (rev 3878)
@@ -116,10 +116,10 @@
               function(e1, e2) arith_bdtDd_int( e1, e2, .Generic ) )
     setMethod("Arith", signature(e1 = "Rcpp_bdtDd", e2 = "numeric" ),
               function(e1, e2) arith_bdtDd_int( e1, as.integer(e2), .Generic ) )
-    setMethod("Arith", signature(e1 = "integer", e2 = "Rcpp_bdtDd"),
-              function(e1, e2) arith_int_bdtDd( e1, e2, .Generic ) )
-    setMethod("Arith", signature(e1 = "numeric", e2 = "Rcpp_bdtDd"),
-              function(e1, e2) arith_int_bdtDd(as.integer(e1), e2, .Generic ) )
+    #setMethod("Arith", signature(e1 = "integer", e2 = "Rcpp_bdtDd"),
+    #          function(e1, e2) arith_int_bdtDd(e1, e2, .Generic ) )
+    #setMethod("Arith", signature(e1 = "numeric", e2 = "Rcpp_bdtDd"),
+    #          function(e1, e2) arith_int_bdtDd(as.integer(e1), e2, .Generic ) )
     setMethod("Compare", signature(e1 = "Rcpp_bdtDd", e2 = "Rcpp_bdtDd" ),
               function(e1, e2) compare_bdtDd_bdtDd( e1, e2, .Generic ) )
     setMethod("Arith", signature(e1 = "Rcpp_bdtDd", e2 = "Rcpp_bdtDt" ),

Modified: pkg/RcppBDT/inst/include/RcppBDT.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDT.h	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/inst/include/RcppBDT.h	2012-11-01 02:42:28 UTC (rev 3878)
@@ -25,10 +25,6 @@
 #include <RcppCommon.h>
 
 // forward declarations and helping module classes 
-class bdtDd;
-class bdtDt;
-class bdtDu;
-class bdtPt;
 RCPP_EXPOSED_CLASS(bdtDd)
 RCPP_EXPOSED_CLASS(bdtDu)
 RCPP_EXPOSED_CLASS(bdtDt)

Modified: pkg/RcppBDT/inst/include/RcppBDTdd.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdd.h	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/inst/include/RcppBDTdd.h	2012-11-01 02:42:28 UTC (rev 3878)
@@ -25,13 +25,12 @@
 class bdtDd {
 
 public:
-    bdtDd() : m_dd(0)			 {} 				// default empty constructor, zero length 
-    //bdtDd(SEXP dd) 			 { m_dd = Rcpp::as<int>(dd); } 	// constructor from SEXP using int
-    bdtDd(long dd) : m_dd(dd)		 {} 	// constructor from day count
+    bdtDd() : m_dd(0)			 {} 			// default empty constructor, zero length 
+    bdtDd(long dd) : m_dd(dd)		 {} 			// constructor from day count
     bdtDd(boost::gregorian::date_duration dd) : m_dd(dd) {} 
     bdtDd(const bdtDd& other) : m_dd(other.m_dd) {}
 
-    long getDays()             { return m_dd.days(); }
+    long getDays()                    { return m_dd.days(); }
 
 private:
     boost::gregorian::date_duration m_dd; 				// private Boost date duration instance

Modified: pkg/RcppBDT/inst/include/RcppBDTdt.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdt.h	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/inst/include/RcppBDTdt.h	2012-11-01 02:42:28 UTC (rev 3878)
@@ -67,6 +67,8 @@
 
     void addDays(unsigned int len) 	 { m_dt += boost::gregorian::date_duration(len); }
     void subtractDays(unsigned int len)  { m_dt -= boost::gregorian::date_duration(len); }
+    void addMonths(int m)                { m_dt += boost::gregorian::months(m); }
+    void addYears(int y) 	         { m_dt += boost::gregorian::years(y); }
 
     // with thanks to Whit Armstong for doing this in his rboostdatetime
     void setIMMDate(int mon, int year)   { 

Modified: pkg/RcppBDT/src/RcppBDTdd.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdd.cpp	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/src/RcppBDTdd.cpp	2012-11-01 02:42:28 UTC (rev 3878)
@@ -22,6 +22,7 @@
 #include <RcppBDT.h>
 
 bdtDd* days(int d)		{ return new bdtDd(boost::gregorian::date_duration(d)); }
+bdtDd* weeks(int w)		{ return new bdtDd(boost::gregorian::weeks(w)); }
 
 bdtDd* arith_bdtDd_bdtDd( const bdtDd& e1, const bdtDd& e2, std::string op) {
     if( ! op.compare("+") ){
@@ -80,7 +81,8 @@
 
     ;
     
-    Rcpp::function( "days",              &days ) ; 
+    Rcpp::function( "days",              &days); 
+    Rcpp::function( "weeks",             &weeks); 
     
     Rcpp::function( "arith_bdtDd_bdtDd",        &arith_bdtDd_bdtDd); 
     Rcpp::function( "arith_bdtDd_int",          &arith_bdtDd_int); 

Modified: pkg/RcppBDT/src/RcppBDTdt.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdt.cpp	2012-10-31 20:39:37 UTC (rev 3877)
+++ pkg/RcppBDT/src/RcppBDTdt.cpp	2012-11-01 02:42:28 UTC (rev 3878)
@@ -164,6 +164,8 @@
 
         .method("addDays", 		&bdtDt::addDays, 		"adds days to given date")
         .method("subtractDays", 	&bdtDt::subtractDays, 		"subtract days from given date")
+        .method("addMonths",            &bdtDt::addMonths,              "adds months to given date")
+        .method("addYears",             &bdtDt::addYears, 	        "add years to given date")
 
         .method("setIMMDate", 		&bdtDt::setIMMDate, 		"sets third Wednesday in given month and year")
 



More information about the Rcpp-commits mailing list