[Rcpp-commits] r3806 - pkg/RcppBDT/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Oct 22 21:00:04 CEST 2012
Author: edd
Date: 2012-10-22 21:00:03 +0200 (Mon, 22 Oct 2012)
New Revision: 3806
Added:
pkg/RcppBDT/demo/RcppBDTdu.R
Log:
forgot to commit this on the weekend
Added: pkg/RcppBDT/demo/RcppBDTdu.R
===================================================================
--- pkg/RcppBDT/demo/RcppBDTdu.R (rev 0)
+++ pkg/RcppBDT/demo/RcppBDTdu.R 2012-10-22 19:00:03 UTC (rev 3806)
@@ -0,0 +1,35 @@
+
+## demo / sketch for duration objects
+
+require(utils, quiet=TRUE, warn=FALSE)
+require(Rcpp, quiet=TRUE, warn=FALSE)
+require(RcppBDT, quiet=TRUE, warn=FALSE)
+
+## ctor with hour, minute, second, fractional seconds (all as ints)
+du <- new(bdtDu, 1, 2, 3, 456)
+print(du) ## not bad: converts to difftime
+
+dn <- new(bdtDu, 0, 1, -3, 123456789) # negative int permitted too, make it negative sign for object
+print(dn) ## not bad: converts to difftime
+
+
+today <- Sys.Date() # base R
+
+## fails: today + du
+
+now <- Sys.time() # base R
+
+## fails as well now + du, but
+print(du$getAddedPosixtime(now))
+
+du$addSeconds(2.2)
+du$addMilliSeconds(3.3)
+du$addMicroSeconds(4.4)
+du$addNanoSeconds(5.5)
+du
+
+print(du$getAddedPosixtime(now))
+
+# add 'du' to something and get a time object ?
+# convert posix time (from Boost) to POSIXct ?
+# more conversions ?
More information about the Rcpp-commits
mailing list