[Rcpp-commits] r3835 - in pkg/RcppBDT: . demo inst inst/include man src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Oct 25 03:49:18 CEST 2012


Author: edd
Date: 2012-10-25 03:49:16 +0200 (Thu, 25 Oct 2012)
New Revision: 3835

Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/demo/00Index
   pkg/RcppBDT/demo/RcppBDTdu.R
   pkg/RcppBDT/inst/NEWS.Rd
   pkg/RcppBDT/inst/include/RcppBDT.h
   pkg/RcppBDT/inst/include/RcppBDTdt.h
   pkg/RcppBDT/man/bdtDu.Rd
   pkg/RcppBDT/man/bdtPt.Rd
   pkg/RcppBDT/src/RcppBDTdt.cpp
   pkg/RcppBDT/src/RcppBDTdu.cpp
Log:
tweaks, simplifications and a bit more documentation


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/ChangeLog	2012-10-25 01:49:16 UTC (rev 3835)
@@ -1,8 +1,18 @@
+2012-10-24  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/include/RcppBDTdt.h: Altered several functions to use
+	boost::gregorian::date more frequently as basic return type and rely
+	on Rcpp::wrap() for conversion, rather than always directly converting
+	* src/RcppBDTdt.cpp: Idem
+
+	* man/bdtDu.Rd: Document new methods for Arithmetic and Comparison
+	* man/bdtPt.Rd: Idem
+
 2012-10-24  Romain Francois  <romain at r-enthusiasts.com>
 
-    * inst/include/RcppBDTdu.h: using const bdtDu& instead of object<bdtDu>
-    * inst/include/RcppBDTpt.h: using const bdtPt& instead of object<bdtPt>
-    
+	* inst/include/RcppBDTdu.h: using const bdtDu& instead of object<bdtDu>
+	* inst/include/RcppBDTpt.h: using const bdtPt& instead of object<bdtPt>
+
 2012-10-23  Romain Francois  <romain at r-enthusiasts.com>
 
 	* src/RcppBDTdu.cpp: using bdtDu* instead of object<bdtDu> for function returns

Modified: pkg/RcppBDT/demo/00Index
===================================================================
--- pkg/RcppBDT/demo/00Index	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/demo/00Index	2012-10-25 01:49:16 UTC (rev 3835)
@@ -1,2 +1,3 @@
 RcppBDT	     Boost Date.Time date functionality demo
 RcppBDTtz    Boost Date.Time timezone functionality demo
+RcppBDTdu    Boost Date.Time duration object demo

Modified: pkg/RcppBDT/demo/RcppBDTdu.R
===================================================================
--- pkg/RcppBDT/demo/RcppBDTdu.R	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/demo/RcppBDTdu.R	2012-10-25 01:49:16 UTC (rev 3835)
@@ -16,22 +16,27 @@
 today <- Sys.Date()    # base R, provides Date
 ## TODO  fails:   today + du
 
-now <- Sys.time()      # base R
+now <- Sys.time()       # base R
+pt <- new(bdtPt) 	# similar to Sys.time()
 ## TODO  fails as well now + du, but this works
-print(du$getAddedPosixtime(now))
+#print(du$getAddedPosixtime(now), tz="UTC")
 
 du$addSeconds(2.2)
 du$addMilliSeconds(3.3)
 du$addMicroSeconds(4.4)
 du$addNanoSeconds(5.5)
 du
+#print(du$getAddedPosixtime(now))
 
-print(du$getAddedPosixtime(now))
+print(pt)
+print(pt + du)
 
+
 # add 'du' to something and get a time object ?
 # convert posix time (from Boost) to POSIXct ?
 # more conversions ?
 
+#print(years(1) + months(2) + days(3))
 print(du + hours(2) + minutes(3) + seconds(4) + nanoseconds(42))
 
 ## use one of several bdtPt ctors

Modified: pkg/RcppBDT/inst/NEWS.Rd
===================================================================
--- pkg/RcppBDT/inst/NEWS.Rd	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/inst/NEWS.Rd	2012-10-25 01:49:16 UTC (rev 3835)
@@ -34,7 +34,6 @@
     initialization easier and more streamlined.
   } 
 }
-
 \section{Changes in version 0.1.0 (2011-01-17)}{
   \itemize{
     \item First CRAN upload (and see ChangeLog for more granular

Modified: pkg/RcppBDT/inst/include/RcppBDT.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDT.h	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/inst/include/RcppBDT.h	2012-10-25 01:49:16 UTC (rev 3835)
@@ -25,10 +25,10 @@
 #include <RcppCommon.h>
 
 // forward declarations and helping module classes 
-class bdtDu ;
-class bdtPt ;
-RCPP_EXPOSED_CLASS(bdtDu) ;
-RCPP_EXPOSED_CLASS(bdtPt) ;
+class bdtDu;
+class bdtPt;
+RCPP_EXPOSED_CLASS(bdtDu)
+RCPP_EXPOSED_CLASS(bdtPt)
 
 // Setting this variable enables use of nanoseconds (as opposed to microseconds)
 // for the maximum resolution; this comes at a cost of 96 bits as opposed to 64 bits

Modified: pkg/RcppBDT/inst/include/RcppBDTdt.h
===================================================================
--- pkg/RcppBDT/inst/include/RcppBDTdt.h	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/inst/include/RcppBDTdt.h	2012-10-25 01:49:16 UTC (rev 3835)
@@ -25,53 +25,51 @@
 class bdtDt {
 
 public:
-    bdtDt()  				{ setFromLocalClock(); } 	// default empty constructor, using epoch
-    bdtDt(SEXP dt) 			{ setDate(dt); } 		// constructor from SEXP using R Date
+    bdtDt()  				 { setFromLocalClock(); } 	// default empty constructor, using epoch
+    bdtDt(SEXP dt) 			 { setDate(dt); } 		// constructor from SEXP using R Date
     bdtDt(int year, int month, int day) : m_dt(year, month, day) { } 	// constructor using year, month, day
     bdtDt(boost::gregorian::date dt) : m_dt(dt) {} 
     bdtDt(const bdtDt& other) : m_dt(other.m_dt) {}
 
     // these set the date from the clock, in local or universal time
-    void setFromLocalClock()		{ m_dt = boost::gregorian::date(boost::gregorian::day_clock::local_day()); }
-    void setFromUTCClock()        	{ m_dt = boost::gregorian::date(boost::gregorian::day_clock::universal_day()); }
-    Rcpp::Date getLocalDay() 		{ return Rcpp::wrap(boost::gregorian::date(boost::gregorian::day_clock::local_day())); }
-    Rcpp::Date getUTCDay() 		{ return Rcpp::wrap(boost::gregorian::date(boost::gregorian::day_clock::universal_day())); }
+    void setFromLocalClock()		 { m_dt = boost::gregorian::date(boost::gregorian::day_clock::local_day()); }
+    void setFromUTCClock()        	 { m_dt = boost::gregorian::date(boost::gregorian::day_clock::universal_day()); }
+    boost::gregorian::date getLocalDay() { return boost::gregorian::date(boost::gregorian::day_clock::local_day()); }
+    boost::gregorian::date getUTCDay() 	 { return boost::gregorian::date(boost::gregorian::day_clock::universal_day()); }
 
     // these extract the requested date portion or representation as an integer
-    int getYear() 			{ return static_cast<int>( m_dt.year() ); }
-    int getMonth() 			{ return static_cast<int>( m_dt.month() ); }
-    int getDay() 			{ return static_cast<int>( m_dt.day() ); }
-    int getDayOfWeek() 			{ return static_cast<int>( m_dt.day_of_week() ); }
-    int getDayOfYear() 			{ return static_cast<int>( m_dt.day_of_year() ); }
+    int getYear() 			 { return static_cast<int>( m_dt.year() ); }
+    int getMonth() 			 { return static_cast<int>( m_dt.month() ); }
+    int getDay() 			 { return static_cast<int>( m_dt.day() ); }
+    int getDayOfWeek() 			 { return static_cast<int>( m_dt.day_of_week() ); }
+    int getDayOfYear() 			 { return static_cast<int>( m_dt.day_of_year() ); }
 
-    void setDate(SEXP dt)		{ m_dt = Rcpp::as<boost::gregorian::date>(dt); }
-    void fromDate(SEXP dt)		{ m_dt = Rcpp::as<boost::gregorian::date>(dt); Rf_warning("'fromDate' is deprecated, use 'setDate'"); }
-    Rcpp::Date getDate()		{ return Rcpp::wrap(m_dt); }
+    void setDate(SEXP dt)		 { m_dt = Rcpp::as<boost::gregorian::date>(dt); }
+    void fromDate(SEXP dt)		 { m_dt = Rcpp::as<boost::gregorian::date>(dt); Rf_warning("'fromDate' is deprecated, use 'setDate'"); }
+    boost::gregorian::date getDate()	 { return m_dt; }
 
-    int getWeekNumber()			{ return m_dt.week_number(); }
-    long getModJulian()			{ return m_dt.week_number(); }
-    long getJulian()			{ return m_dt.week_number(); }
+    int getWeekNumber()			 { return m_dt.week_number(); }
+    long getModJulian()			 { return m_dt.week_number(); }
+    long getJulian()			 { return m_dt.week_number(); }
 
     // construct end-of-month and first-of-next-monthm returning a boost::gregorian::date object
-    void setEndOfMonth()		{ m_dt = m_dt.end_of_month(); } 
-    boost::gregorian::date getEndOfMonth() { 
-        				  return m_dt.end_of_month(); } 
-    void setFirstOfNextMonth()		{ m_dt = m_dt.end_of_month() + boost::gregorian::days(1); } 
-    boost::gregorian::date getFirstOfNextMonth() { 
-                                          return m_dt.end_of_month() + boost::gregorian::days(1); }
+    void setEndOfMonth()		 { m_dt = m_dt.end_of_month(); } 
+    boost::gregorian::date getEndOfMonth() { return m_dt.end_of_month(); } 
+    void setFirstOfNextMonth()		 { m_dt = m_dt.end_of_month() + boost::gregorian::days(1); } 
+    boost::gregorian::date getFirstOfNextMonth() { return m_dt.end_of_month() + boost::gregorian::days(1); }
 
-    void setEndOfBizWeek() 		{ 
+    void setEndOfBizWeek() 		 { 
         m_dt += boost::gregorian::days_until_weekday(m_dt, boost::gregorian::greg_weekday(boost::gregorian::Friday)); 
     }
-    Rcpp::Date getEndOfBizWeek() 	{ 
-        return Rcpp::wrap( m_dt += boost::gregorian::days_until_weekday(m_dt, boost::gregorian::greg_weekday(boost::gregorian::Friday) )); 
+    boost::gregorian::date getEndOfBizWeek() 	 { 
+        return m_dt += boost::gregorian::days_until_weekday(m_dt, boost::gregorian::greg_weekday(boost::gregorian::Friday) ); 
     }
 
-    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 addDays(unsigned int len) 	 { m_dt += boost::gregorian::date_duration(len); }
+    void subtractDays(unsigned int len)  { m_dt -= boost::gregorian::date_duration(len); }
 
     // with thanks to Whit Armstong for doing this in his rboostdatetime
-    void setIMMDate(int mon, int year)  { 
+    void setIMMDate(int mon, int year)   { 
         m_dt = boost::gregorian::nth_day_of_the_week_in_month(boost::gregorian::nth_day_of_the_week_in_month::third, 
                                                               boost::gregorian::Wednesday, mon).get_date(year); 
     }

Modified: pkg/RcppBDT/man/bdtDu.Rd
===================================================================
--- pkg/RcppBDT/man/bdtDu.Rd	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/man/bdtDu.Rd	2012-10-25 01:49:16 UTC (rev 3835)
@@ -3,6 +3,16 @@
 \alias{Rcpp_bdtDu-class}
 \alias{show,Rcpp_bdtDu-method}
 \alias{format,Rcpp_bdtDu-method}
+\alias{arith_bdtDu_bdtDu}
+\alias{arith_bdtDu_bdtPt}
+\alias{arith_bdtDu_int}
+\alias{compare_bdtDu_bdtDu}
+\alias{hours}
+\alias{microseconds}
+\alias{milliseconds}
+\alias{minutes}
+\alias{nanoseconds}
+\alias{seconds}
 \docType{package}
 \title{Rcpp module bdtDu for binding of Boost Date_Time duration functionality}
 \description{
@@ -15,6 +25,17 @@
   be at a nano-second granularity; there may be platforms not permitting
   this.
 }
+\usage{
+hours(...)
+microseconds(...)
+milliseconds(...)
+minutes(...)
+nanoseconds(...)
+seconds(...)
+}
+\arguments{
+  \item{...}{suitable argument, often an integer, denoting one unit of the reference duration component}
+}
 \section{Method}{
   \describe{
     \item{show}{\code{signature(x = "Rcpp_bdtDu")}: prints a (BDTdu) duration class object}

Modified: pkg/RcppBDT/man/bdtPt.Rd
===================================================================
--- pkg/RcppBDT/man/bdtPt.Rd	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/man/bdtPt.Rd	2012-10-25 01:49:16 UTC (rev 3835)
@@ -3,6 +3,8 @@
 \alias{Rcpp_bdtPt-class}
 \alias{show,Rcpp_bdtPt-method}
 \alias{format,Rcpp_bdtPt-method}
+\alias{arith_bdtPt_bdtDu}
+\alias{compare_bdtPt_bdtPt}
 \docType{package}
 \title{Rcpp module bdtPt for binding of Boost Date_Time ptime functionality}
 \description{

Modified: pkg/RcppBDT/src/RcppBDTdt.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdt.cpp	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/src/RcppBDTdt.cpp	2012-10-25 01:49:16 UTC (rev 3835)
@@ -34,37 +34,37 @@
     }
 }
 
-Rcpp::Date getIMMDate(bdtDt *d, int mon, int year) { 				// does not use bdtDt pointer, but need for RCPP_MODULE use
-    return Rcpp::wrap( boost::gregorian::nth_day_of_the_week_in_month(boost::gregorian::nth_day_of_the_week_in_month::third, 
-                                                                      boost::gregorian::Wednesday, mon).get_date(year) );
+boost::gregorian::date getIMMDate(bdtDt *d, int mon, int year) { 				// does not use bdtDt pointer, but need for RCPP_MODULE use
+    return boost::gregorian::nth_day_of_the_week_in_month(boost::gregorian::nth_day_of_the_week_in_month::third, 
+                                                          boost::gregorian::Wednesday, mon).get_date(year);
 }
 
-Rcpp::Date getNthDayOfWeek(bdtDt *d, int nthday, int dow, int mon, int year) { 	// does not use bdtDt pointer, but need for RCPP_MODULE use
+boost::gregorian::date getNthDayOfWeek(bdtDt *d, int nthday, int dow, int mon, int year) { 	// does not use bdtDt pointer, but need for RCPP_MODULE use
     boost::gregorian::nth_day_of_the_week_in_month 
         ans_generator(static_cast<boost::date_time::nth_kday_of_month<boost::gregorian::date>::week_num>(nthday), dow, mon);
-    return Rcpp::wrap(ans_generator.get_date(year));
+    return ans_generator.get_date(year);
 }
 
-Rcpp::Date getLastDayOfWeekInMonth(bdtDt *d, int weekday, int mon, int year) {	// does not use bdtDt pointer, but need for RCPP_MODULE use
+boost::gregorian::date getLastDayOfWeekInMonth(bdtDt *d, int weekday, int mon, int year) {	// does not use bdtDt pointer, but need for RCPP_MODULE use
     boost::gregorian::last_day_of_the_week_in_month lwdm(weekday, mon);
-    return Rcpp::wrap(lwdm.get_date(year));
+    return lwdm.get_date(year);
 }
 
-Rcpp::Date getFirstDayOfWeekInMonth(bdtDt *d, int weekday, int mon, int year) {	// does not use bdtDt pointer, but need for RCPP_MODULE use
+boost::gregorian::date getFirstDayOfWeekInMonth(bdtDt *d, int weekday, int mon, int year) {	// does not use bdtDt pointer, but need for RCPP_MODULE use
     boost::gregorian::first_day_of_the_week_in_month fwdm(weekday, mon);
-    return Rcpp::wrap(fwdm.get_date(year));
+    return fwdm.get_date(year);
 }
 
-Rcpp::Date getFirstDayOfWeekAfter(bdtDt *d, int weekday, SEXP date) {		// does not use bdtDt pointer, but need for RCPP_MODULE use
+boost::gregorian::date getFirstDayOfWeekAfter(bdtDt *d, int weekday, SEXP date) {		// does not use bdtDt pointer, but need for RCPP_MODULE use
     boost::gregorian::first_day_of_the_week_after fdaf(weekday);
     boost::gregorian::date dt = Rcpp::as<boost::gregorian::date>(date);
-    return Rcpp::wrap(fdaf.get_date(dt));
+    return fdaf.get_date(dt);
 }
 
-Rcpp::Date getLastDayOfWeekBefore(bdtDt *d, int weekday, SEXP date) {		// does not use bdtDt pointer, but need for RCPP_MODULE use
+boost::gregorian::date getLastDayOfWeekBefore(bdtDt *d, int weekday, SEXP date) {		// does not use bdtDt pointer, but need for RCPP_MODULE use
     boost::gregorian::first_day_of_the_week_before fdab(weekday);
     boost::gregorian::date dt = Rcpp::as<boost::gregorian::date>(date);
-    return Rcpp::wrap(fdab.get_date(dt));
+    return fdab.get_date(dt);
 }
 
 RCPP_MODULE(bdtDtMod) {

Modified: pkg/RcppBDT/src/RcppBDTdu.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTdu.cpp	2012-10-25 00:42:11 UTC (rev 3834)
+++ pkg/RcppBDT/src/RcppBDTdu.cpp	2012-10-25 01:49:16 UTC (rev 3835)
@@ -101,16 +101,16 @@
         .method("getAddedPosixtime",      &bdtDu::getAddedPosixtime,	  "adds duration to given posix time and returns posix time")
     ;
     
-    Rcpp::function( "hours", 		&hours ) ; 
-    Rcpp::function( "minutes", 	&minutes ) ; 
-    Rcpp::function( "seconds", 	&seconds ) ; 
-    Rcpp::function( "milliseconds", 	&milliseconds ) ; 
-    Rcpp::function( "microseconds", 	&microseconds ) ;
-    Rcpp::function( "nanoseconds", 	&nanoseconds ) ; 
+    Rcpp::function( "hours",            &hours ) ; 
+    Rcpp::function( "minutes",          &minutes ) ; 
+    Rcpp::function( "seconds",          &seconds ) ; 
+    Rcpp::function( "milliseconds",     &milliseconds ) ; 
+    Rcpp::function( "microseconds",     &microseconds ) ;
+    Rcpp::function( "nanoseconds",      &nanoseconds ) ; 
     
-    Rcpp::function( "arith_bdtDu_bdtDu", 	&arith_bdtDu_bdtDu ) ; 
+    Rcpp::function( "arith_bdtDu_bdtDu",        &arith_bdtDu_bdtDu ) ; 
     Rcpp::function( "arith_bdtDu_int",          &arith_bdtDu_int ) ; 
-    Rcpp::function( "compare_bdtDu_bdtDu",	&compare_bdtDu_bdtDu );
+    Rcpp::function( "compare_bdtDu_bdtDu",      &compare_bdtDu_bdtDu );
 
 }
 



More information about the Rcpp-commits mailing list