Skip to content

Instantly share code, notes, and snippets.

Avatar

David Holstius dholstius

  • Bay Area Air Quality Management District
  • San Francisco Bay Area
  • Twitter @dholstius
View GitHub Profile
View gist:2885513
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 Jun 6, 2012
How to fetch datapoints with the pachube R package
View gist:2885515
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 Jun 6, 2012
How to fetch datapoints with the pachube R package
View R-pachube-getDatapoints
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 Jun 6, 2012
How to fetch data points with the pachube R package
View pachube-getDatapoints.R
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 Jun 6, 2012
Installing devtools and then cosm
View feed_history.R
require(cosm)
key <- 'bZW0wu4jbqMrkzHhap...' # your API key here
z <- feed_history(58785, key, duration='3hours')
plot(z)
@dholstius
dholstius / stat_rollapplyr.R
Created Jun 8, 2012
Apply a rolling mean (or other function) to a ggplot2 layer
View stat_rollapplyr.R
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 Jun 21, 2012
Extended historical queries with the cosm R package
View download-bfs.R
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 Jun 22, 2012
Read CSV records from a file written by serlog.py
View read.serlog.R
#' 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 Jun 22, 2012
Configure WiFly RN-XV as a serial-to-http bridge
View config
// 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 Jun 24, 2012
Personal .Rprofile of David Holstius
View .Rprofile
# 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)