This release just arranges things neatly before Leonardo Silvestri and I may shake things up with a possible shift to doing it all in S4 as we may need the added rigour for
nanotime object operations for use in his ztsdb project.
Changes in version 0.1.2 (2017-03-27)
as.integer64function is now exported as well.
This release adds an improved default display format always showing nine digits of fractional seconds. It also changes the
print() method to call
format() first, and we started to provide some better default
Ops methods. These fixes were suggested by Matt Dowle. We also corrected a small issue which could lead to precision loss in formatting as pointed out by Leonardo Silvestri.
Changes in version 0.1.1 (2017-02-04)
The default print method was updated to use formated output, and a new new converter
Several 'Ops' method are now explicitly defined allowing casting of results (rather than falling back on bit64 behaviour)
nanotime relies on the RcppCCTZ package for high(er) resolution time parsing and formatting: R itself stops a little short of a microsecond. And it uses the bit64 package for the actual arithmetic: time at this granularity is commonly represented at (integer) increments (at nanosecond resolution) relative to an offset, for which the standard epoch of Januar 1, 1970 is used.
int64 types are a perfect match here, and bit64 gives us an
integer64. Naysayers will point out some technical limitations with R's S3 classes, but it works pretty much as needed here.
The one thing we did not have was Windows support. RcppCCTZ and the CCTZ library it uses need real C++11 support, and the
g++-4.9 compiler used on Windows falls a little short lacking inter alia a suitable
std::get_time() implementation. Enter Dan Dillon who ported this from LLVM's libc++ which lead to Sunday's RcppCCTZ 0.2.0 release.
And now we have all our ducks in a row: everything works on Windows too. The next paragraph summarizes the changes for both this release as well as the initial one last month:
Changes in version 0.1.0 (2017-01-10)
Added "mocked up" demo with nanosecond delay networking analysis
Added data.frame support
Changes in version 0.0.1 (2016-12-15)
Initial CRAN upload.
Package is functional and provides examples.
R has excellent tools for dates and times. The
POSIXct classes (as well as the 'wide' representation in
POSIXlt) are versatile, and a lot of useful tooling has been built around them.
POSIXct is implemented as a
double with fractional seconds since the epoch. Given the 53 bits accuracy, it leaves just a bit less than microsecond resolution. Which is good enough for most things.
But more and more performance measurements, latency statistics, ... are now measured more finely, and we need nanosecond resolution. For which commonly an
integer64 is used to represent nanoseconds since the epoch.
And while R does not a native type for this, the bit64 package by Jens Oehlschlägel offers a performant one implemented as a lightweight S3 class. So this package uses this
integer64 class, along with two helper functions for parsing and formatting, respectively, at nano-second resolution from the RcppCCTZ package which wraps the CCTZ library from Google. CCTZ is a modern C++11 library extending the (C++11-native)
R> x <- nanotime("1970-01-01T00:00:00.000000001+00:00") R> print(x) integer64  1 R> format(x)  "1970-01-01T00:00:00.000000001+00:00" R> cat("x+1 is: ") x+1 is: R> x <- x + 1 R> print(x) integer64  2 R> format(x)  "1970-01-01T00:00:00.000000002+00:00" R>
R> options("width"=60) R> v <- nanotime(Sys.time()) + 1:5 R> v integer64  1481505724483583001 1481505724483583002  1481505724483583003 1481505724483583004  1481505724483583005 R> format(v)  "2016-12-12T01:22:04.483583001+00:00"  "2016-12-12T01:22:04.483583002+00:00"  "2016-12-12T01:22:04.483583003+00:00"  "2016-12-12T01:22:04.483583004+00:00"  "2016-12-12T01:22:04.483583005+00:00" R>
R> z <- zoo(cbind(A=1:5, B=5:1), v) R> options("nanotimeFormat"="%d %b %H:%M:%E*S") ## override default R> z A B 12 Dec 01:47:55.812513001 1 5 12 Dec 01:47:55.812513002 2 4 12 Dec 01:47:55.812513003 3 3 12 Dec 01:47:55.812513004 4 2 12 Dec 01:47:55.812513005 5 1 R>
The bit64 package (by Jens Oehlschlägel) supplies the
integer64 type used to store the nanosecond resolution time as (positive or negative) offsets to the epoch of January 1, 1970. The RcppCCTZ package supplies the formatting and parsing routines based on the (modern C++) library CCTZ from Google.
It (at least currently) requires RcppCCTZ to parse and format nanosecond resolution time objects from / to text --- and this package is on Linux and OS X only due to its use of system time zoneinfo. The requirement could be relaxed in the future by rewriting formating and parsing code. Contributions are welcome.
The package is not yet on CRAN. Until it gets there, or to install the development versions, it can also be installed via a standard
install.packages("RcppCCTZ") # need 0.1.0 or later remotes::install_github("eddelbuettel/nanotime")
If you prefer
install.packages() (as I do), use the version from the ghrr drat:
install.packages("drat") # easier repo access + creation drat:::add("ghrr") # make it known install.packages("nanotime") # install it
If and when it gets to CRAN you will be able to do