Skip to content

Instantly share code, notes, and snippets.

@dholstius
Created June 21, 2012 00:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholstius/2963186 to your computer and use it in GitHub Desktop.
Save dholstius/2963186 to your computer and use it in GitHub Desktop.
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)
while (TRUE) {
t0 <- t0 - duration
message("Requesting: end = ", t0)
result <- getDatapoints(feed, key, datastreams='2h', end=t0, start=t0-duration)
if (is.null(result)) break
z <- c(z, result)
}
plot(z, main=feed$title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment