Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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