Fast POSIXct in R

as.POSIXct() can be slow as molasses. Have you ever tried to import a million timestamps in R? Luckily, Simon Urbanek has gifted useRs with fasttime, an R library for quickly parsing timestamps using string manipulation. Install it with:

install.packages('fasttime', type='source', repos='')

fasttime contains one function, fastPOSIXct, that is restricted to parsing GMT timestamps after 1970-01-01. For many of us dealing with lots of recently acquired time-series data, that’s no problem.

Continue reading

Posted in Code | Tagged

Cosm R package

Here we go, an R package with a couple of helpful functions to help you pull your data from the Cosm API:

  • feed_detail() returns JSON-like data as nested lists.
  • feed_history() returns a zoo object representing selected datastreams.

Why zoo objects? Well, zoo is one of the most widely relied-on R packages. It’s a building block, much like the sp package for spatial data. If you’re working with totally ordered observations—like repeated measurements from one sensor or device—then it seems likely that you’ll encounter it sooner or later. (The zoo FAQ and the Time Series R task view explain more about related packages.) R’s “baked-in” ts objects and methods are designed for regular time series, and let’s face it, when you’re logging sensor measurements from a microcontroller, there’s no way your measurements are exactly equally spaced. But they are totally ordered.

Here’s a quick example of what your R code might look like using this package:

If you want to install it and play around, I suggest first installing Hadley Wickham’s excellent devtools package. Then you can just install directly from my GitHub repository, like so: