Created
June 16, 2013 21:03
-
-
Save mhkeller/5793439 to your computer and use it in GitHub Desktop.
An example querying the FMS Treasury database using R.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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