Skip to content

Instantly share code, notes, and snippets.

View dholstius's full-sized avatar

David Holstius dholstius

  • Bay Area Air Quality Management District
  • San Francisco Bay Area
  • X @dholstius
View GitHub Profile
key <- 'bZW0wu4jbqMrkzHhapw8E9...' # use your API key here
t0 <- ISOdate(2012, 05, 23, hour=19, tz="America/Los_Angeles")
z <- getDatapoints(58785, 'large', key, start=t0, interval=30, duration='12hours')
@dholstius
dholstius / gist:2885515
Created June 6, 2012 23:36
How to fetch datapoints with the pachube R package
key <- 'bZW0wu4jbqMrkzHhapw8E9...' # use your API key here
t0 <- ISOdate(2012, 05, 23, hour=19, tz="America/Los_Angeles")
z <- getDatapoints(58785, 'large', key, start=t0, interval=30, duration='12hours')
plot(z)
@dholstius
dholstius / R-pachube-getDatapoints
Created June 6, 2012 23:37
How to fetch datapoints with the pachube R package
key <- 'bZW0wu4jbqMrkzHhapw8E9...' # use your API key here
t0 <- ISOdate(2012, 05, 23, hour=19, tz="America/Los_Angeles")
z <- getDatapoints(58785, 'large', key, start=t0, interval=30, duration='12hours')
plot(z)
@dholstius
dholstius / pachube-getDatapoints.R
Created June 6, 2012 23:37
How to fetch data points with the pachube R package
require(pachube)
key <- 'bZW0wu4jbqMrkzHhapw8E9...' # use your API key here
t0 <- ISOdate(2012, 05, 23, hour=19, tz="America/Los_Angeles")
z <- getDatapoints(58785, 'large', key, start=t0, interval=30, duration='12hours')
plot(z)
@dholstius
dholstius / feed_history.R
Created June 6, 2012 23:43
Installing devtools and then cosm
require(cosm)
key <- 'bZW0wu4jbqMrkzHhap...' # your API key here
z <- feed_history(58785, key, duration='3hours')
plot(z)
@dholstius
dholstius / stat_rollapplyr.R
Created June 8, 2012 22:50
Apply a rolling mean (or other function) to a ggplot2 layer
require(ggplot2)
require(proto)
StatRollApplyR <- proto(ggplot2:::Stat, {
required_aes <- c("x", "y")
default_geom <- function(.) GeomLine
objname <- "rollapplyr"
calculate_groups <- function(., data, scales, ...) {
.super$calculate_groups(., data, scales, ...)
}
calculate <- function(., data, scales, width, FUN, fill=NA, ...) {
@dholstius
dholstius / download-bfs.R
Created June 21, 2012 00:44
Extended historical queries with the cosm R package
require('cosm')
if (!exists('key')) key <- readline('API key: ')
feed <- getFeed(58537, key)
print(feed$description)
t0 <- Sys.time()
duration <- 60 * 60 * 24 * 7 # one week
z <- getDatapoints(feed, key, datastreams='2h', end=t0, start=t0-duration)
@dholstius
dholstius / read.serlog.R
Created June 22, 2012 18:39
Read CSV records from a file written by serlog.py
#' read.serlog
#'
#' Read CSV records from a file written by serlog.py
#'
#' @param file filename
#' @param varnames column names for the resulting \link{zoo} object
#' @export
read.serlog <- function(file, varnames) {
require(zoo)
options(digits.secs=3)
@dholstius
dholstius / config
Created June 22, 2012 21:51
Configure WiFly RN-XV as a serial-to-http bridge
// Join the wireless network
set wlan ssid WIFI_NETWORK
set wlan phrase WIFI_PASSWORD
set wlan join 1
join
// Set the real-time clock
set time
show time
set time enable 1
@dholstius
dholstius / .Rprofile
Created June 24, 2012 20:36
Personal .Rprofile of David Holstius
# Repositories
options(repos = c(
CRAN = 'http://cran.cnr.Berkeley.edu',
CRANExtra = 'http://www.stats.ox.ac.uk/pub/RWin/'
)
)
# Millisecond precision with POSIXt objects, strptime(), etc.
options(digits.secs=3)