Integration with R

rztsdb package installation

To run ztsdb queries from the R command line, the package rztsdb (not yet on CRAN) needs to be installed.

rztsdb also is dependent on the latest version or the package nanotime. The latest version is not yet on CRAN, so here too an install from the repository is necessary.

If ztsdb has been installed with make install (see Installing), then the package should install straightforwardly like this from an R session:


If ztsdb has not been installed, the GCC environment variables must be set prior to running the above code in order to find:

R command line

If ztsdb was not installed, make sure before running R that is either in a place where it can be found by the loader with ldconfig or that LD_LIBRARY_PATH is specified as in the previous section.

Once in R, load the rztsdb package:


Then create a connection object to a ztsdb instance specifying the port on which that instance is listening on (in this example the ztsdb instance is listening on port 15001):

c1 <- connection("", 15001)

Once a connection is established, it is possible to write any ztsdb code on the right hand side of a connection that is followed by the query operator ?; for example:

### remotely create a 10x3 time-series and assign it to 'z':
c1 ? (z <<- zts( + 1:10*as.duration(1e6)), 1:30, dimnames=list(NULL, c("a","b","c"))

### query the newly created time-series:
c1 ? z            # get the complete times-series 'z'
c1 ? tail(z)      # get the last 6 observations from 'z'
c1 ? z[,"a"]      # get the column 'a' from 'z'