Interface to 'Sunlight' Foundation 'APIs'

Interface to 'APIs' for US government data previously under the 'Sunlight' Foundation, now under 'ProPublica' (< https://www.propublica.org/datastore/'apis'>), and Open States (< http://docs.openstates.org/en/latest/api/>). Functions are provided to interact with each of the routes in each API.


Build Status codecov.io rstudio mirror downloads cran version

rsunlight is a collection of functions to search and acquire data from the various APIs that used to be housed under Sunlight Labs, but which are now housed under ProPublica.

rsunlight wraps functions in APIs for:

  • Congress API (cg) - Run by ProPublica
  • Open States API (os) - Run by OpenStates foundation

Functions that wrap these sets of APIs will be prefixed by cg or os for the different methods listed above:

  • cg + fxn
  • os + fxn

where fxn would be a function to a interface with a specific API.

You need API keys for Propublica APIs. Get them at https://www.propublica.org/datastore/apis

You need an API key for the OpenStates API. Get it at https://openstates.org/api/register/

We set up the functions so that you can use either env vars, or R options. For env vars, put an entry in your .Renviron file with the names PROPUBLICA_API_KEY and OPEN_STATES_KEY.

From CRAN

install.packages("rsunlight")

Or development version from Github

devtools::install_github("ropengov/rsunlight")
library("rsunlight")

Congress API

Search for congress members by chamber and state

cg_members_state_district('senate', 'RI')
#> # A tibble: 2 x 16
#>   id     name   first_name middle_name last_name suffix role  gender party
#>   <chr>  <chr>  <chr>      <chr>       <chr>     <chr>  <chr> <chr>  <chr>
#> 1 W0008… Sheld… Sheldon    <NA>        Whitehou… <NA>   Sena… M      D
#> 2 R0001… Jack … Jack       <NA>        Reed      <NA>   Sena… M      D
#> # ... with 7 more variables: times_topics_url <chr>, twitter_id <chr>,
#> #   facebook_account <chr>, youtube_id <chr>, seniority <chr>,
#> #   next_election <chr>, api_uri <chr>

Search for committees by congress and chamber

cg_committees(115, "senate")[[1]]$committees[[1]]
#> $id
#> [1] "SCNC"
#>
#> $name
#> [1] "Caucus on International Narcotics Control"
#>
#> $chamber
#> [1] "Senate"
#>
#> $url
#> [1] "http://www.drugcaucus.senate.gov/"
#>
#> $api_uri
#> [1] "https://api.propublica.org/congress/v1/115/senate/committees/SCNC.json"
#>
#> $chair
#> [1] "Charles E. Grassley"
#>
#> $chair_id
#> [1] "G000386"
#>
#> $chair_party
#> [1] "R"
#>
#> $chair_state
#> [1] "IA"
#>
#> $chair_uri
#> [1] "https://api.propublica.org/congress/v1/members/G000386.json"
#>
#> $ranking_member_id
#> [1] "F000062"
#>
#> $subcommittees
#> list()

Open States API

Bill Search - Search for bills with the term agriculture, in Texas, and in the upper chamber.

os_billsearch(terms = 'agriculture', state = 'tx', chamber = 'upper')
#> # A tibble: 26 x 10
#>    title  created_at updated_at id    chamber state session type  subjects
#>  * <chr>  <chr>      <chr>      <chr> <chr>   <chr> <chr>   <chr> <chr>
#>  1 Relat… 2017-03-1… 2017-06-0… TXB0… upper   tx    85      bill  <NA>
#>  2 Recog… 2017-02-2… 2017-06-0… TXB0… upper   tx    85      reso… <NA>
#>  3 Recog… 2017-02-2… 2017-06-0… TXB0… upper   tx    85      reso… <NA>
#>  4 Relat… 2017-01-3… 2017-06-0… TXB0… upper   tx    85      bill  <NA>
#>  5 Relat… 2015-03-0… 2016-04-2… TXB0… upper   tx    84      bill  <NA>
#>  6 Relat… 2015-03-1… 2015-07-0… TXB0… upper   tx    84      bill  <NA>
#>  7 Urgin… 2015-05-1… 2016-04-2… TXB0… upper   tx    84      conc… <NA>
#>  8 Relat… 2015-03-1… 2015-03-2… TXB0… upper   tx    84      bill  <NA>
#>  9 Relat… 2015-03-1… 2015-03-2… TXB0… upper   tx    84      bill  <NA>
#> 10 Relat… 2015-03-0… 2015-03-1… TXB0… upper   tx    84      bill  <NA>
#> # ... with 16 more rows, and 1 more variable: bill_id <chr>

Legislator Search - Search for Republican legislators in Nevada

os_legislatorsearch(state = 'nv', party = 'republican')
#> # A tibble: 24 x 26
#>    last_name updated_at   full_name  id    first_name middle_name district
#>  * <chr>     <chr>        <chr>      <chr> <chr>      <chr>       <chr>
#>  1 Hambrick  2018-05-14 … John Hamb… NVL0… John       ""          2
#>  2 Woodbury  2018-05-14 … Melissa W… NVL0… Melissa    ""          23
#>  3 Ellison   2018-05-14 … John Elli… NVL0… John C.    ""          33
#>  4 Hansen    2018-05-14 … Ira Hansen NVL0… Ira        ""          32
#>  5 Anderson  2018-05-14 … Paul Ande… NVL0… Paul       ""          13
#>  6 Oscarson  2018-05-14 … James Osc… NVL0… James      ""          36
#>  7 Wheeler   2018-05-14 … Jim Wheel… NVL0… Jim        ""          39
#>  8 Titus     2018-05-14 … Robin L. … NVL0… Robin L.   ""          38
#>  9 Edwards   2018-05-14 … Chris Edw… NVL0… Chris      ""          19
#> 10 Kramer    2018-05-14 … Al Kramer  NVL0… Al         ""          40
#> # ... with 14 more rows, and 19 more variables: state <chr>,
#> #   votesmart_id <chr>, party <chr>, email <chr>, all_ids <chr>,
#> #   leg_id <chr>, active <lgl>, transparencydata_id <chr>, nickname <chr>,
#> #   photo_url <chr>, url <chr>, country <chr>, created_at <chr>,
#> #   level <chr>, chamber <chr>, offices <chr>, `+address` <chr>,
#> #   suffixes <chr>, csrfmiddlewaretoken <chr>

Meta

  • Please report any issues or bugs.
  • License: MIT
  • Get citation information for rsunlight in R doing citation(package = 'rsunlight')
  • Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

News

rsunlight 0.7.0

Below changes mostly in response to APIs moving from Sunlight Labs to ProPublica. (#64) (#67)

NEW FEATURES

  • Now importing packages crul, tibble, and data.table and no longer importing httr, stringr
  • New functions cg_bills_recent, cg_bills_recent_member, cg_bills_recent_subject, cg_bills_upcoming, cg_committee, cg_committee_comms, cg_committee_hearings, cg_committees_comms_category, cg_committees_comms_chamber, cg_committees_comms_date, cg_floor_actions_date, cg_floor_actions_recent, cg_members, cg_members_bill_cosponsors, cg_members_compare_bill_sponsors, cg_members_compare_votes, cg_members_leaving, cg_members_new, cg_members_state_district, cg_members_votes, cg_nomination, cg_nominations_category, cg_nominations_state, cg_state_party_countes, cg_statements_date, cg_statements_member, cg_statements_recent, cg_statements_search, cg_statements_subject, cg_statements_subjects, cg_votes_date, cg_votes_explanations, cg_votes_explanations_category, cg_votes_explanations_member, cg_votes_recent, cg_votes_senatenoms, cg_votes_type, os_committee, os_committees, os_district, os_districts, os_legislator, os_legislatorgeo
  • replace httr with crul (#65)

DEFUNCT

  • Now defunct because API services are gone: cg_votes, cg_districts, cg_documents, cg_floor_updates, cg_hearings, cg_legislators, cw_dates, cw_phrases, cw_text, cw_timeseries (#64) (#67)

rsunlight 0.4.2

DEFUNCT

  • Influence Explorer defunct as of January 2016. Thus, ie_ functions are now defunct in this package. (#57)

rsunlight 0.4

NEW FEATURES

  • API keys can be now be stored as both an env var and an option. (#54)
  • Most outputs by default are data.frames, and use the dplyr::tbl_df style (#50)
  • New function added cg_documents() for the Congressional documents route (#35)

MINOR IMPROVEMENTS

  • rCharts dependency removed. This package is still not on CRAN, so this is simpler. In addition, CRAN wants all deps in a "mainstream" CRAN like repo. (#53)
  • Started test suite (#32)
  • Added ability to vectorize some parameters in some functions (#21)
  • Added description of n parameter in the cw_dates() function man page (#2)
  • Non base R functions are now explicitly imported, from methods and utils packages (#55)
  • Set base URLs for each of the four Sunlight APIs in one place, less error prone in case they change their base URLs (#46)

BUG FIXES

  • Fixed bug due to unconventional object ([) returned when no data found in some Sunlight API routes (#51)
  • Bug fixes to bills functions (#42)

rsunlight 0.3

NEW FEATURES

  • Complete reworking of the package, function names, et.
  • New Congress API, in functions cg_*
  • Transparency API is now in function ie_*
  • Beware: those that have used this package before. Most or all function names have changed. This version is very breaking.

rsunlight 0.2

NEW FEATURES

  • Changed package name to rsunlight, only holds functions to interact with Sunlight Labs APIs. NYtimes congress API functions moved to a new pacakge rtimes.

rsunlight 0.1

NEW FEATURES

  • released to CRAN

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rsunlight")

0.7.0 by Scott Chamberlain, 9 months ago


https://github.com/ropengov/rsunlight


Report a bug at https://github.com/ropengov/rsunlight/issues


Browse source code at https://github.com/cran/rsunlight


Authors: Scott Chamberlain [aut, cre] , Thomas J. Leeper [ctb]


Documentation:   PDF Manual  


Task views:


MIT + file LICENSE license


Imports methods, utils, crul, plyr, jsonlite, stringr, tibble, data.table

Suggests testthat

Enhances ggplot2


See at CRAN