Pachube.R
Apr 12, 2012
1 minute read

I wanted to share a script I use for analyzing sensor data stored on Pachube. I use the open source stats software R which is available on most platforms. The simple script below consists of only two functions: Pachube.query and Pachube.fetch. Query allows me to inspect a particular feed which can be made of zero or more datastreams. Pachube.fetch retrieves data points up to a given number of hours in the past.

Authentication happens through the getURL call. By specifying netrc ‘optional’ RCurl looks for a separate .netrc file in your home directory:

machine api.pachube.com
  login _your login_
  password _your password_

Replace _your login_ and _your password_ with the appropriate information.

#AirQualityEgg Example

Save the file locally as “Pachube.R” and launch R. You can load the script as follows:

source("Pachube.R")

Once loaded, query a feed as follows:

Pachube.query(feed=48307)

This will display the datastreams available from an #AirQualityEgg assembled in London during a workshop. To retrieve the NO2 data issue the following command

Pachube.fetch(feed=48307, datastream="NO2", hours=24)

The maximum number of data points available through the historical query API is described here. Writing these was good fun and a way for me to keep learning R…


Creative Commons License This material is licensed under a Creative Commons Attribution 3.0 Unported License

Back to posts


comments powered by Disqus