Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Created June 16, 2013 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhkeller/5793439 to your computer and use it in GitHub Desktop.
Save mhkeller/5793439 to your computer and use it in GitHub Desktop.
An example querying the FMS Treasury database using R.
#!/usr/bin/env Rscript
library(plyr)
library(utils)
library(RJSONIO)
library(RCurl)
treasury <- function(sql) {
url = paste('https://box.scraperwiki.com/cc7znvq/47d80ae900e04f2/sql/?q=', URLencode(sql), sep = '')
handle <- getCurlHandle()
body <- getURL(url, curl = handle)
if (200 == getCurlInfo(handle)$response.code) {
ldply(
fromJSON(body),
function(row) {as.data.frame(t(row))}
)
} else {
stop(body)
}
}
if (!interactive()) {
print('Operating cash balances for May 22, 2013')
print(treasury('SELECT * FROM "t1" WHERE "date" = \'2013-05-22\';'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment