OpenStates from R via API: watch your elected representatives

June 10, 2011

(This article was first published on Recology, and kindly contributed to R-bloggers)

I am writing some functions to acquire data from the OpenStates project, via their API. They have a great support community at Google Groups as well.

On its face this post is not obviously about ecology or evolution, but well, our elected representatives do, so to speak, hold our environment in a noose, ready to let the Earth hang any day.

Code I am developing is over at Github.

Here is an example of its use in R, in this case using the Bill Search option (billsearch.R on my Github site), and in this case you do not provide your API key in the function call, but instead put it in your .Rprofile file, which is called when you open R. We are searching here for the term ‘agriculture’ in Texas (‘tx’), in the ‘upper’ chamber.

> temp <- billsearch('agriculture', state = 'tx', chamber = 'upper')
> length(temp)
[1] 21
> temp[[1]]
[1] "Congratulating John C. Padalino of El Paso for being appointed to the United States Department of Agriculture."
[1] "2010-08-11 07:59:46"
[1] "2010-09-02 03:34:39"
[1] "upper"
[1] "tx"
[1] "81"
[1] "resolution"
[1] "Resolutions"
[1] "Other"
[1] "SR 1042"

Apparently, the first bill (SR 2042, see $bill_id at the bottom of the list output) that came up was to congratulate John Paladino for being appointed to the USDA.

The other function I have ready is getting basic metadata on a state, called statemetasearch.

I plan to develop more functions for all the possible API calls to the OpenStates project.

To leave a comment for the author, please follow the link and comment on their blog: Recology. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)