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:
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:
knitr, a new package by Yihui Xie, takes (most of) the pain out of Sweave. Beautiful defaults, sensible coding style, and wonderful built-in caching. I’m writing all my reports with it. And adding him to my list of must-follow R users (along with Hadley).