Learn R Programming

rsunlight

NOTE: Capitol Words API is defunct

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.

Install rsunlight

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.

Copy Link

Version

Install

install.packages('rsunlight')

Monthly Downloads

37

Version

0.7.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Last Published

May 15th, 2018

Functions in rsunlight (0.7.0)

ie_entities

This function is defunct.
cg_documents

Search for data on documents
cg_floor_updates

Search for data on upcoming bills.
cg_legislators

Search for legislators.
ie_contracts

This function is defunct.
ie_lobbying

This function is defunct.
members

Members functions
ie_organizations

This function is defunct.
ie_earmarks

This function is defunct.
ie_contr

This function is defunct.
ie_contr_bundled

This function is defunct.
cg_state_party_countes

state party counts
os_committee

Lookup a Committee by ID
nominations

nominations methods
cg_bills_upcoming

Search for upcoming bills
cw_text

Full-text search the congressional record for instances of a word or phrase
cg_districts

Get districts for a latitude/longitude or zips
ie_grants

This function is defunct.
cw_phrases

List the top phrases for a facet.
ie_faca

This function is defunct.
os_committees

Search OpenStates committees
cg_votes

This function is defunct.
cw_timeseries

Find the popularity of a phrase over a period of time.
floor_actions

floor actions methods
ie_epa

This function is defunct.
ie_sectors

This function is defunct.
os_billsearch

Search OpenStates bills.
os_billlookup

Lookup bills on OpenStates.
ie_politicians

This function is defunct.
ie_individuals

This function is defunct.
sessions

Congressional sessions, up to the 114th (2015-2016)
os_legislatorsearch

Search Legislators on OpenStates.
os_statemetasearch

Search OpenStates metadata
ie_industries

This function is defunct.
statements

statements methods
os_legislator

Lookup a Legislator by ID
os_legislatorgeo

Lookup Legislators geospatially
os_district

Get OpenStates districts boundary by boundary id
rsunlight-defunct

Defunct functions in rsunlight
os_districts

Search OpenStates districts
votes

votes methods
rsunlight-package

Methods for retreiving data from APIs that were previously under Sulight Labs
cg_bills

Search bills
cg_bills_recent

Get recent bills
cg_bills_recent_subject

Get recent bills by subject
committees

committees methods
cw_dates

Find the popularity of a phrase over a period of time
cg_bill_related_bills

Get related bills for a specific bill
cg_bills_recent_member

Get recent bills by member id
cg_bill_cosponsors

Get cosponsors for a specific bill
cg_bill

Get a specific bill
cg_bill_subjects_search

Search for bill subjects that contain a specified term
cg_bill_amendments

Search for data on amendments for a specific bill
cg_bill_subjects

Get Library of Congress-assigned subjects about a particular bill
cg_hearings

Search for data on hearings