[Rcpp-commits] r2854 - in pkg/RcppBDT: . R demo man src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 9 00:29:50 CET 2011


Author: edd
Date: 2011-01-09 00:29:50 +0100 (Sun, 09 Jan 2011)
New Revision: 2854

Added:
   pkg/RcppBDT/man/bdtEnv.Rd
   pkg/RcppBDT/man/constants.Rd
Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/R/bdt.R
   pkg/RcppBDT/R/zzz.R
   pkg/RcppBDT/demo/RcppBDT.R
   pkg/RcppBDT/man/RcppBDT-package.Rd
   pkg/RcppBDT/src/RcppBDT.cpp
Log:
added documentation
defined a number of R-level constants in the package: Sun, Mon, ..., Sat and Jan, Feb, ..., Dec
a few tweaks, edits, variable renamings when adding documentation


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2011-01-08 23:22:25 UTC (rev 2853)
+++ pkg/RcppBDT/ChangeLog	2011-01-08 23:29:50 UTC (rev 2854)
@@ -1,15 +1,26 @@
 2011-01-08  Dirk Eddelbuettel  <edd at debian.org>
 
+	* man/RcppBDT-package.Rd: updated
+	* man/dateFunctions.Rd: added documentation on functions
+	* man/constants.Rd: added documentation on constants defined
+	* man/bdtEnv.Rd: added documentation for bdtEnv variable
+
 	* src/RcppBDT.cpp: Added two new functions for date of first and last
 	weekday in a given month and year (eg first Friday in Jan 2011)
 
+	* R/zzz.R:
+	  - defined a number of constants: Sun, Mon, Tue, ... , Sat as well
+  	    as Jan, Feb, ..., Dec and first, second, ..., fifth
+	  - added some documentation on enviroment
+
 	* R/bdt.R:
 	  - added function to export core object for access
 	  - changed functions to access core object via per-pack. environment
 	  - added functions for first/last day-of-week in month/year
+	  - some variables renamed in the process of writing documentation
 
 	* demo/RcppBDT.R: updated to keep in sync with other changes
-	
+
 2011-01-06  Dirk Eddelbuettel  <edd at dexter>
 
 	* inst/include/RcppBDT.h: Added paragraph about the UseWithString

Modified: pkg/RcppBDT/R/bdt.R
===================================================================
--- pkg/RcppBDT/R/bdt.R	2011-01-08 23:22:25 UTC (rev 2853)
+++ pkg/RcppBDT/R/bdt.R	2011-01-08 23:29:50 UTC (rev 2854)
@@ -22,43 +22,43 @@
     bdtEnv$bdt
 }
 
-getEndOfBizWeek <- function(d = Sys.Date()) {
-    stopifnot(inherits(d, "Date"))
-    bdtEnv$bdt$getEndOfBizWeek(d)
+getEndOfBizWeek <- function(date = Sys.Date()) {
+    stopifnot(inherits(date, "Date"))
+    bdtEnv$bdt$getEndOfBizWeek(date)
 }
 
-getEndOfMonth <- function(d = Sys.Date()) {
-    stopifnot(inherits(d, "Date"))
-    bdtEnv$bdt$getEndOfMonth(d)
+getEndOfMonth <- function(date = Sys.Date()) {
+    stopifnot(inherits(date, "Date"))
+    bdtEnv$bdt$getEndOfMonth(date)
 }
 
-getYear <- function(d = Sys.Date()) {
-    stopifnot(inherits(d, "Date"))
-    bdtEnv$bdt$fromDate(d)
+getYear <- function(date = Sys.Date()) {
+    stopifnot(inherits(date, "Date"))
+    bdtEnv$bdt$fromDate(date)
     bdtEnv$bdt$getYear()
 }
 
-getMonth <- function(d = Sys.Date()) {
-    stopifnot(inherits(d, "Date"))
-    bdtEnv$bdt$fromDate(d)
+getMonth <- function(date = Sys.Date()) {
+    stopifnot(inherits(date, "Date"))
+    bdtEnv$bdt$fromDate(date)
     bdtEnv$bdt$getMonth()
 }
 
-getDay <- function(d = Sys.Date()) {
-    stopifnot(inherits(d, "Date"))
-    bdtEnv$bdt$fromDate(d)
+getDay <- function(date = Sys.Date()) {
+    stopifnot(inherits(date, "Date"))
+    bdtEnv$bdt$fromDate(date)
     bdtEnv$bdt$getDay()
 }
 
-getDayOfWeek <- function(d = Sys.Date()) {
-    stopifnot(inherits(d, "Date"))
-    bdtEnv$bdt$fromDate(d)
+getDayOfWeek <- function(date = Sys.Date()) {
+    stopifnot(inherits(date, "Date"))
+    bdtEnv$bdt$fromDate(date)
     bdtEnv$bdt$getDayOfWeek()
 }
 
-getDayOfYear <- function(d = Sys.Date()) {
-    stopifnot(inherits(d, "Date"))
-    bdtEnv$bdt$fromDate(d)
+getDayOfYear <- function(date = Sys.Date()) {
+    stopifnot(inherits(date, "Date"))
+    bdtEnv$bdt$fromDate(date)
     bdtEnv$bdt$getDayOfYear()
 }
 
@@ -66,8 +66,8 @@
     bdtEnv$bdt$getIMMDate(mon, year)
 }
 
-getNthDayOfMthWeek <- function(nthday, mthweek, mon, year) {
-    bdtEnv$bdt$getNthDayMthWeek(nthday, mthweek, mon, year)
+getNthDayOfWeek <- function(nthday, dow, mon, year) {
+    bdtEnv$bdt$getNthDayOfWeek(nthday, dow, mon, year)
 }
 
 getLastDayOfWeekInMonth <- function(nthday, mon, year) {
@@ -77,3 +77,11 @@
 getFirstDayOfWeekInMonth <- function(nthday, mon, year) {
     bdtEnv$bdt$getFirstDayOfWeekInMonth(nthday, mon, year)
 }
+
+getFirstDayOfWeekAfter <- function(dow, date) {
+    bdtEnv$bdt$getFirstDayOfWeekAfter(dow, date)
+}
+
+getLastDayOfWeekBefore <- function(dow, date) {
+    bdtEnv$bdt$getLastDayOfWeekBefore(dow, date)
+}

Modified: pkg/RcppBDT/R/zzz.R
===================================================================
--- pkg/RcppBDT/R/zzz.R	2011-01-08 23:22:25 UTC (rev 2853)
+++ pkg/RcppBDT/R/zzz.R	2011-01-08 23:29:50 UTC (rev 2854)
@@ -22,21 +22,48 @@
 ## new environment for our package, local to the package
 bdtEnv <- new.env(parent=emptyenv())
 
+## a simple alternative to enum type in C++ -- we could also have
+## these as parts of a data.frame
+Sun <- 0
+Mon <- 1
+Tue <- 2
+Wed <- 3
+Thu <- 4
+Fri <- 5
+Sat <- 6
+
+## likewise, identifiers for the months
+Jan <- 1
+Feb <- 2
+Mar <- 3
+Apr <- 4
+May <- 5
+Jun <- 6
+Jul <- 7
+Aug <- 8
+Sep <- 9
+Oct <- 10
+Nov <- 11
+Dec <- 12
+
+## and for sequences
+first <- 1
+second <- 2
+third <- 3
+fourth <- 4
+fifth <- 5
+
 .onLoad <- function (lib, pack) {
 
     ## we need the methods package
     require(methods, quiet=TRUE, warn=FALSE)
 
-    ## new environment for our package, stored in global env
-    #.RcppBDTenv <<- new.env(parent=emptyenv())
-
-    ## Create internal variables
-    #.RcppBDTenv$BDTDate <- Module("bdt")$date
-    #.RcppBDTenv$bdt <- new(.RcppBDTenv$BDTDate)
-    #.RcppBDTenv$bdt$setFromUTC()
-
+    ## store an instance of the date class as BDTDate
     bdtEnv$BDTDate <- Module("bdt")$date
+    ## and create a new object of the class as bdt
     bdtEnv$bdt <- new(bdtEnv$BDTDate)
     bdtEnv$bdt$setFromUTC()
 
+    #attach(daysOfWeek)
+
 }

Modified: pkg/RcppBDT/demo/RcppBDT.R
===================================================================
--- pkg/RcppBDT/demo/RcppBDT.R	2011-01-08 23:22:25 UTC (rev 2853)
+++ pkg/RcppBDT/demo/RcppBDT.R	2011-01-08 23:29:50 UTC (rev 2854)
@@ -5,10 +5,11 @@
 
     ## this uses the pretty-printing the Rcpp module logic to show all
     ## available functions and their docstring (symbol now in per-package env)
-    #print(BDTDate)
+    #print(RcppBDT::bdtEnv$BDTDate)
 
     ## first init a base objects for uses for the functions below
     ## using the instance stored in an internal environment
+    ## alternative form: RcppBDT$bdt)
     bd <- getBDT()
 
     ## alternative constructors: see R/zzz.R
@@ -36,10 +37,12 @@
     cat("1st of next month : ", format(bd$getFirstOfNextMonth()), "\n")
 
     cat("\nDemo of functions\n")
-    cat("IMM Date Dec 2010 : ", format(getIMMDate(12, 2010)), "\n")
-    cat("3rd Wed Dec 2010  : ", format(getNthDayOfMthWeek(3, 3, 12, 2010)), "\n")
-    cat("Last Sat Dec 2010 : ", format(getLastDayOfWeekInMonth(6, 12, 2010)), "\n")
-    cat("First Sat Dec 2010: ", format(getFirstDayOfWeekInMonth(6, 12, 2010)), "\n")
+    cat("IMM Date Dec 2010 : ", format(getIMMDate(Dec, 2010)), "\n")
+    cat("3rd Wed Dec 2010  : ", format(getNthDayOfWeek(third, Wed, Dec, 2010)), "\n")
+    cat("Last Sat Dec 2010 : ", format(getLastDayOfWeekInMonth(Sat, Dec, 2010)), "\n")
+    cat("First Sat Dec 2010: ", format(getFirstDayOfWeekInMonth(Sat, Dec, 2010)), "\n")
+    cat("First Wed in 2011 : ", format(getFirstDayOfWeekAfter(Wed, as.Date("2010-12-31"))), "\n")
+    cat("Last Wed in 2010  : ", format(getLastDayOfWeekBefore(Wed, as.Date("2010-12-31"))), "\n")
 }
 
 demo.RcppBDT()

Modified: pkg/RcppBDT/man/RcppBDT-package.Rd
===================================================================
--- pkg/RcppBDT/man/RcppBDT-package.Rd	2011-01-08 23:22:25 UTC (rev 2853)
+++ pkg/RcppBDT/man/RcppBDT-package.Rd	2011-01-08 23:29:50 UTC (rev 2854)
@@ -2,30 +2,17 @@
 \alias{RcppBDT-package}
 \alias{RcppBDT}
 \docType{package}
-\title{
-  Bindings for Boost Date_Time
-}
+\title{Bindings for Boost Date_Time}
 \description{
   This package provides R with access to Boost Date_Time
   functonality by using Rcpp modules. Currently only Date functionality 
-  is covered.  
+  is covered.
 }
 \details{
-\tabular{ll}{
-Package: \tab RcppBDT\cr
-Type: \tab Package\cr
-Version: \tab 0.0.1\cr
-Date: \tab $Date$\cr
-License: \tab GPL (>= 2)\cr
-LazyLoad: \tab yes\cr
+  Please consult the Boost documentation for (copious) details on the
+  Date_Time library.
 }
-}
-\author{
-  Dirk Eddelbuettel <edd at debian.org>
-  Maintainer: Dirk Eddelbuettel <edd at debian.org>
-}
-\references{
-  Boost Date_Time: \url{http://www.boost.org/doc/html/date_time.html}
-}
+\author{Dirk Eddelbuettel \email{edd at debian.org}}
+\references{Boost Date_Time: \url{http://www.boost.org/doc/html/date_time.html}}
 \keyword{package}
 

Added: pkg/RcppBDT/man/bdtEnv.Rd
===================================================================
--- pkg/RcppBDT/man/bdtEnv.Rd	                        (rev 0)
+++ pkg/RcppBDT/man/bdtEnv.Rd	2011-01-08 23:29:50 UTC (rev 2854)
@@ -0,0 +1,16 @@
+\name{bdtEnv}
+\alias{bdtEnv}
+\docType{package}
+\title{Bindings for Boost Date_Time}
+\description{
+  The \verb{bdtEnv} environment contains the reference class instance
+  created by means of Rcpp modules, as well as an object instance.
+}
+\details{
+  Please consult the Boost documentation for (copious) details on the
+  Date_Time library. See the Rcpp-modules vignette for details on Rcpp
+  modules. 
+}
+\author{Dirk Eddelbuettel \email{edd at debian.org}}
+\references{Boost Date_Time: \url{http://www.boost.org/doc/html/date_time.html}}
+\keyword{package}

Added: pkg/RcppBDT/man/constants.Rd
===================================================================
--- pkg/RcppBDT/man/constants.Rd	                        (rev 0)
+++ pkg/RcppBDT/man/constants.Rd	2011-01-08 23:29:50 UTC (rev 2854)
@@ -0,0 +1,51 @@
+\name{RcppBDT-constants}
+\alias{RcppBDT-constants}
+\alias{Sun}
+\alias{Mon}
+\alias{Tue}
+\alias{Wed}
+\alias{Thu}
+\alias{Fri}
+\alias{Sat}
+\alias{Jan}
+\alias{Feb}
+\alias{Mar}
+\alias{Apr}
+\alias{May}
+\alias{Jun}
+\alias{Jul}
+\alias{Aug}
+\alias{Sep}
+\alias{Oct}
+\alias{Nov}
+\alias{Dec}
+\alias{first}
+\alias{second}
+\alias{third}
+\alias{fourth}
+\alias{fifth}
+\docType{package}
+\title{Constants for date functions with Boost Date_Time}
+\description{
+  This constants are provided for convenience. In the C++ sources,
+  enumeration types are used for days of the week, months of the year as
+  well as the ordering terms.
+
+  Similar package-level constants are provided here as well. This should
+  be considered as experimental and may be withdrawn in a later version
+  of the package.  
+}
+\details{
+  \verb{Sun}, \verb{Mon}, \verb{Tue}, ..., \verb{Sat} can be used instead of the values 0 to 6.
+
+  \verb{Jan}, \verb{Feb}, ..., \verb{Dec} can be used instead of the values 1 to 12.
+
+  \verb{first}, \verb{second}, ..., \verb{fifth} can be used instead of the values 1 to 5. 
+
+  We use the same values as the Boost source code. In other words,
+  Sunday is 0, Monday is 1 and so on.  Months, however, start at 1 for
+  January. 
+}
+\author{Dirk Eddelbuettel \email{edd at debian.org}}
+\references{Boost Date_Time: \url{http://www.boost.org/doc/html/date_time.html}}
+\keyword{package}

Modified: pkg/RcppBDT/src/RcppBDT.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDT.cpp	2011-01-08 23:22:25 UTC (rev 2853)
+++ pkg/RcppBDT/src/RcppBDT.cpp	2011-01-08 23:29:50 UTC (rev 2854)
@@ -114,7 +114,7 @@
     return Rcpp::wrap(ans_generator.get_date(year));
 }
 
-Rcpp::Date Date_nthDayOfMthWeek(boost::gregorian::date *d, int nthday, int mthweek, int mon, int year) {
+Rcpp::Date Date_nthDayOfWeek(boost::gregorian::date *d, int nthday, int mthweek, int mon, int year) {
     nth_dow ans_generator(static_cast<boost::date_time::nth_kday_of_month<boost::gregorian::date>::week_num>(mthweek), nthday, mon);
     return Rcpp::wrap(ans_generator.get_date(year));
 }
@@ -129,6 +129,18 @@
     return Rcpp::wrap(fwdm.get_date(year));
 }
 
+Rcpp::Date Date_firstDayOfWeekAfter(boost::gregorian::date *d, int weekday, SEXP date) {
+    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));
+}
+
+Rcpp::Date Date_lastDayOfWeekBefore(boost::gregorian::date *d, int weekday, SEXP date) {
+    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));
+}
+
 RCPP_MODULE(bdt) {
 
     using namespace boost::gregorian;
@@ -192,11 +204,14 @@
     .method("setIMMDate", &date_immDate, "sets third Wednesday in given month and year")
     .method("getIMMDate", &Date_immDate, "return third Wednesday in given month and year")
 
-    .method("getNthDayMthWeek", &Date_nthDayOfMthWeek, "return nth week's given day-of-week in given month and year")
+    .method("getNthDayOfWeek", &Date_nthDayOfWeek, "return nth week's given day-of-week in given month and year")
 
     .method("getLastDayOfWeekInMonth", &Date_lastDayOfWeekInMonth, "return date of last day-of-week in given month and year")
     .method("getFirstDayOfWeekInMonth", &Date_firstDayOfWeekInMonth, "return date of last day-of-week in given month and year")
 
+    .method("getFirstDayOfWeekAfter", &Date_firstDayOfWeekAfter, "return date of first day-of-week after given date")
+    .method("getLastDayOfWeekBefore", &Date_lastDayOfWeekBefore, "return date of last day-of-week before given date")
+
     ;
 
 }



More information about the Rcpp-commits mailing list