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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 11 20:47:58 CET 2011


Author: edd
Date: 2011-01-11 20:47:58 +0100 (Tue, 11 Jan 2011)
New Revision: 2862

Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/DESCRIPTION
   pkg/RcppBDT/R/bdt.R
   pkg/RcppBDT/R/zzz.R
   pkg/RcppBDT/demo/RcppBDT.R
   pkg/RcppBDT/man/bdt.Rd
Log:
changed (with a tip of the hat to wls inside Rcpp on R-forge) how the default instance is set up in zzz.R
with corresponding changes in affected files
and updated version, now 0.0.3


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2011-01-11 19:27:57 UTC (rev 2861)
+++ pkg/RcppBDT/ChangeLog	2011-01-11 19:47:58 UTC (rev 2862)
@@ -1,3 +1,12 @@
+2011-01-11  Dirk Eddelbuettel  <edd at debian.org>
+
+	* DESCRIPTION (Version): bumped version to 0.0.3
+	
+	* R/zzz.R: change initialization after borrowing a better approach
+	from John's wls package in the Rcpp repo on R-Forge: now 'bdt' is
+	the default instance of the reference class, and the module code is
+	available via 'bdtMod'
+
 2011-01-08  Dirk Eddelbuettel  <edd at debian.org>
 
 	* man/RcppBDT-package.Rd: updated

Modified: pkg/RcppBDT/DESCRIPTION
===================================================================
--- pkg/RcppBDT/DESCRIPTION	2011-01-11 19:27:57 UTC (rev 2861)
+++ pkg/RcppBDT/DESCRIPTION	2011-01-11 19:47:58 UTC (rev 2862)
@@ -1,7 +1,7 @@
 Package: RcppBDT
 Type: Package
 Title: Rcpp bindings for the Boost Date_Time library 
-Version: 0.0.2
+Version: 0.0.3
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois
 Maintainer: Dirk Eddelbuettel <edd at debian.org>

Modified: pkg/RcppBDT/R/bdt.R
===================================================================
--- pkg/RcppBDT/R/bdt.R	2011-01-11 19:27:57 UTC (rev 2861)
+++ pkg/RcppBDT/R/bdt.R	2011-01-11 19:47:58 UTC (rev 2862)
@@ -18,70 +18,66 @@
 ## You should have received a copy of the GNU General Public License
 ## along with RcppBDT.  If not, see <http://www.gnu.org/licenses/>.
 
-getBDT <- function() {
-    bdtEnv$bdt
-}
-
 getEndOfBizWeek <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdtEnv$bdt$getEndOfBizWeek(date)
+    bdt$getEndOfBizWeek(date)
 }
 
 getEndOfMonth <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdtEnv$bdt$getEndOfMonth(date)
+    bdt$getEndOfMonth(date)
 }
 
 getYear <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdtEnv$bdt$fromDate(date)
-    bdtEnv$bdt$getYear()
+    bdt$fromDate(date)
+    bdt$getYear()
 }
 
 getMonth <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdtEnv$bdt$fromDate(date)
-    bdtEnv$bdt$getMonth()
+    bdt$fromDate(date)
+    bdt$getMonth()
 }
 
 getDay <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdtEnv$bdt$fromDate(date)
-    bdtEnv$bdt$getDay()
+    bdt$fromDate(date)
+    bdt$getDay()
 }
 
 getDayOfWeek <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdtEnv$bdt$fromDate(date)
-    bdtEnv$bdt$getDayOfWeek()
+    bdt$fromDate(date)
+    bdt$getDayOfWeek()
 }
 
 getDayOfYear <- function(date = Sys.Date()) {
     stopifnot(inherits(date, "Date"))
-    bdtEnv$bdt$fromDate(date)
-    bdtEnv$bdt$getDayOfYear()
+    bdt$fromDate(date)
+    bdt$getDayOfYear()
 }
 
 getIMMDate <- function(mon, year) {     # defined as third Wednesday
-    bdtEnv$bdt$getIMMDate(mon, year)
+    bdt$getIMMDate(mon, year)
 }
 
 getNthDayOfWeek <- function(nthday, dow, mon, year) {
-    bdtEnv$bdt$getNthDayOfWeek(nthday, dow, mon, year)
+    bdt$getNthDayOfWeek(nthday, dow, mon, year)
 }
 
 getLastDayOfWeekInMonth <- function(nthday, mon, year) {
-    bdtEnv$bdt$getLastDayOfWeekInMonth(nthday, mon, year)
+    bdt$getLastDayOfWeekInMonth(nthday, mon, year)
 }
 
 getFirstDayOfWeekInMonth <- function(nthday, mon, year) {
-    bdtEnv$bdt$getFirstDayOfWeekInMonth(nthday, mon, year)
+    bdt$getFirstDayOfWeekInMonth(nthday, mon, year)
 }
 
 getFirstDayOfWeekAfter <- function(dow, date) {
-    bdtEnv$bdt$getFirstDayOfWeekAfter(dow, date)
+    bdt$getFirstDayOfWeekAfter(dow, date)
 }
 
 getLastDayOfWeekBefore <- function(dow, date) {
-    bdtEnv$bdt$getLastDayOfWeekBefore(dow, date)
+    bdt$getLastDayOfWeekBefore(dow, date)
 }

Modified: pkg/RcppBDT/R/zzz.R
===================================================================
--- pkg/RcppBDT/R/zzz.R	2011-01-11 19:27:57 UTC (rev 2861)
+++ pkg/RcppBDT/R/zzz.R	2011-01-11 19:47:58 UTC (rev 2862)
@@ -18,9 +18,14 @@
 ## You should have received a copy of the GNU General Public License
 ## along with RcppBDT.  If not, see <http://www.gnu.org/licenses/>.
 
+## This and the code below in onLoad() owe some gratitude to
+## the wls package inside the Rcpp repository on R-forge
+##
+## grab the namespace of this package for use below
+.NAMESPACE <- environment()
 
-## new environment for our package, local to the package
-bdtEnv <- new.env(parent=emptyenv())
+# dummy module, will be replaced later
+bdt <- new( "Module" )
 
 ## a simple alternative to enum type in C++ -- we could also have
 ## these as parts of a data.frame
@@ -58,12 +63,13 @@
     ## we need the methods package
     require(methods, quiet=TRUE, warn=FALSE)
 
-    ## 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()
+    unlockBinding("bdt", .NAMESPACE)    	# unlock
+    bdtMod <- Module( "bdt" )$date		# get the module code
+    bdt <- new(bdtMod)                  	# default constructor for reference instance
+    bdt$setFromUTC()                    	# but set a default value
+    assign("bdt", bdt, .NAMESPACE)      	# assign the reference instance
+    assign("bdtMod", bdtMod, .NAMESPACE)  	# and the module
+    lockBinding( "bdt", .NAMESPACE)		# and lock
+}
 
-    #attach(daysOfWeek)
 
-}

Modified: pkg/RcppBDT/demo/RcppBDT.R
===================================================================
--- pkg/RcppBDT/demo/RcppBDT.R	2011-01-11 19:27:57 UTC (rev 2861)
+++ pkg/RcppBDT/demo/RcppBDT.R	2011-01-11 19:47:58 UTC (rev 2862)
@@ -4,37 +4,35 @@
     require(RcppBDT, quiet=TRUE, warn=FALSE)
 
     ## this uses the pretty-printing the Rcpp module logic to show all
-    ## available functions and their docstring (symbol now in per-package env)
-    #print(RcppBDT::bdtEnv$BDTDate)
+    ## available functions and their docstring (symbol is not exported)
+    #print(bdtMod)
 
-    ## 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()
+    ## we use a base object 'bdt' for the functions below
+    ## by using the instance stored in the environment
+    ##
+    ## alternatively could construct a new instance from bdtMod, see R/zzz.R
 
-    ## alternative constructors: see R/zzz.R
-
     cat("Demo of setters\n");
     ## conversions from string commented out, see inst/include/RcppBDT.h for details
-    ##bd$fromString("2010-10-02"); 	cat("From 2010-10-02   : ", format(bd$getDate()), "\n")
-    ##bd$fromUndelString("20101003");    cat("From 20101003     : ", format(bd$getDate()), "\n")
-    bd$setFromUTC(); 			cat("From curr. UTC    : ", format(bd$getDate()), "\n")
-    bd$setFromLocalClock();		cat("From curr. local  : ", format(bd$getDate()), "\n")
-    bd$setEndOfMonth(); 		cat("end of month      : ", format(bd$getDate()), "\n")
-    bd$setFirstOfNextMonth(); 		cat("1st of next Month : ", format(bd$getDate()), "\n")
-    bd$addDays(4);                      cat("plus four days    : ", format(bd$getDate()), "\n")
-    bd$subtractDays(3);                 cat("minus three days  : ", format(bd$getDate()), "\n")
+    ##bdt$fromString("2010-10-02"); 	cat("From 2010-10-02   : ", format(bdt$getDate()), "\n")
+    ##bdt$fromUndelString("20101003");  cat("From 20101003     : ", format(bdt$getDate()), "\n")
+    bdt$setFromUTC(); 			cat("From curr. UTC    : ", format(bdt$getDate()), "\n")
+    bdt$setFromLocalClock();		cat("From curr. local  : ", format(bdt$getDate()), "\n")
+    bdt$setEndOfMonth(); 		cat("end of month      : ", format(bdt$getDate()), "\n")
+    bdt$setFirstOfNextMonth(); 		cat("1st of next Month : ", format(bdt$getDate()), "\n")
+    bdt$addDays(4);                     cat("plus four days    : ", format(bdt$getDate()), "\n")
+    bdt$subtractDays(3);                cat("minus three days  : ", format(bdt$getDate()), "\n")
 
-    bd$setIMMDate(12, 2010); 		cat("IMM Date Dec 2010 : ", format(bd$getDate()), "\n")
-    bd$setEndOfBizWeek();  		cat("end of biz week   : ", format(bd$getDate()), "\n")
+    bdt$setIMMDate(12, 2010); 		cat("IMM Date Dec 2010 : ", format(bdt$getDate()), "\n")
+    bdt$setEndOfBizWeek();  		cat("end of biz week   : ", format(bdt$getDate()), "\n")
 
     cat("\nDemo of getters\n")
     ## now just functions that return values to R
-    cat("From curr. local  : ", format(bd$getLocalClock()), "\n")
-    bd$setFromLocalClock();
-    cat("end of biz week   : ", format(bd$getEndOfBizWeek()), "\n")
-    cat("end of of month   : ", format(bd$getEndOfMonth()), "\n")
-    cat("1st of next month : ", format(bd$getFirstOfNextMonth()), "\n")
+    cat("From curr. local  : ", format(bdt$getLocalClock()), "\n")
+    bdt$setFromLocalClock();
+    cat("end of biz week   : ", format(bdt$getEndOfBizWeek()), "\n")
+    cat("end of of month   : ", format(bdt$getEndOfMonth()), "\n")
+    cat("1st of next month : ", format(bdt$getFirstOfNextMonth()), "\n")
 
     cat("\nDemo of functions\n")
     cat("IMM Date Dec 2010 : ", format(getIMMDate(Dec, 2010)), "\n")

Modified: pkg/RcppBDT/man/bdt.Rd
===================================================================
--- pkg/RcppBDT/man/bdt.Rd	2011-01-11 19:27:57 UTC (rev 2861)
+++ pkg/RcppBDT/man/bdt.Rd	2011-01-11 19:47:58 UTC (rev 2862)
@@ -1,11 +1,15 @@
 \name{bdt}
 \alias{bdt}
+\alias{bdtMod}
 \docType{package}
 \title{Default object for RcppBDT Boost Date_Time binding}
 \description{
   The \verb{bdt} variable is a default instance of the reference class
   created by means of Rcpp modules.
 
+  The \verb{bdtMod} variable is an instance of the class created by Rcpp
+  modules; see \code{print(bdtMod)} for available methods.
+  
   New instances can be created using either the default constructor
   (without argument) or the constructor using year, month, date arguments.
 }



More information about the Rcpp-commits mailing list