Interface to 'Sunlight' Foundation 'APIs'

Interface to three 'Sunlight' Foundation 'APIs' (http:// for government data, including the Congress 'API' 'v3', the Capitol Words 'API', and the Open States 'API'. 'Sunlight' Foundation is a 'nonpartison' 'nonprofit' that collects and provides data on government activities, and those that influence government. Functions are provided to interact with each of the three 'APIs'.

rsunlight is a collection of functions to search and acquire data from the various Sunlight Labs APIs for government data, at

rsunlight wraps functions in APIs for:

  • Congress API (cg)
  • Open States API (os)
  • Capitol Words API (cw)

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

  • cg + fxn
  • os + fxn
  • cw + fxn

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

Please get your own API keys if you plant to use these functions for Sunlight Labs (

Data from the Sunlight Foundation API is provided by Sunlight Foundation.

You need API keys for Sunlight Foundation APIs. Please get your own API keys if you plant to use these functions for Sunlight Labs ( 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 name SUNLIGHT_LABS_KEY, so the full thing would be SUNLIGHT_LABS_KEY=<key>. For R options, put the key in your .Rprofile file like options(SunlightLabsKey = "key"). Both are called on R startup, and then you don't have to enter your API key for each run of a function.

Note that Puerto Rico is not included in Sunlight Foundation data.



Or development version from Github

cg_districts(latitude = 35.778788, longitude = -78.787805)
#> <Sunlight data>
#>    Dimensions:   [1 X 2]
#>   state district
#> 1    NC        2
out <- cg_legislators(last_name = 'Reed')

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

os_billsearch(terms = 'agriculture', state = 'tx', chamber = 'upper')
#> <Sunlight data>
#>    Dimensions:   [320 X 10]
#>                                                                          title
#> 1  Relating to certain committees and programs to develop the wine industry in
#> 2  Relating to a waiver of fees by the Department of Agriculture and the Parks
#> 3  Urging the United States Department of Agriculture Food and Nutrition Servi
#> 4  Relating to the designation of an office in the Department of Agriculture t
#> 5  Relating to the office of water and the water advisory committee in the Dep
#> 6  Relating to establishing an agriculture ombudsman office in the Department 
#> 7  Relating to authorizing the issuance of revenue bonds to fund capital proje
#> 8  Relating to authorizing the issuance of revenue bonds to fund capital proje
#> 9  Relating to authorizing the issuance of revenue bonds to fund capital proje
#> 10 Relating to authorizing the issuance of revenue bonds to fund capital proje
#> ..                                                                         ...
#> Variables not shown: created_at (chr), updated_at (chr), id (chr), chamber
#>      (chr), state (chr), session (chr), type (list), subjects (list),
#>      bill_id (chr)

Search for Republican legislators in Nevada

os_legislatorsearch(state = 'nv', party = 'republican')
#> <Sunlight data>
#>    Dimensions:   [36 X 26]
#>    last_name          updated_at           full_name        id  first_name
#> 1    O'Neill 2015-12-15 08:41:55 Philip P.K. O'Neill NVL000291      Philip
#> 2    Dooling 2015-12-15 08:42:35 Victoria A. Dooling NVL000273 Victoria A.
#> 3      Fiore 2015-12-15 08:42:36       Michele Fiore NVL000252     Michele
#> 4    Edwards 2015-12-15 08:42:36       Chris Edwards NVL000287       Chris
#> 5   Hambrick 2015-12-15 08:42:36       John Hambrick NVL000082        John
#> 6   Woodbury 2015-12-15 08:42:36    Melissa Woodbury NVL000105     Melissa
#> 7    Gardner 2015-12-15 08:42:36    David M. Gardner NVL000290    David M.
#> 8     Nelson 2015-12-15 08:42:36     Erven T. Nelson NVL000270    Erven T.
#> 9     Kirner 2015-12-15 08:42:36        Randy Kirner NVL000131       Randy
#> 10 Armstrong 2015-12-15 08:42:36     Derek Armstrong NVL000292       Derek
#> ..       ...                 ...                 ...       ...         ...
#> Variables not shown: middle_name (chr), district (chr), state (chr), party
#>      (chr), email (chr), all_ids (list), leg_id (chr), active (lgl),
#>      transparencydata_id (chr), nickname (chr), photo_url (chr), url
#>      (chr), created_at (chr), chamber (chr), offices (list), suffixes
#>      (chr), votesmart_id (chr), country (chr), level (chr), +address
#>      (chr), csrfmiddlewaretoken (chr)

Get a list of how many times the phrase "united states" appears in the Congressional Record in each month between January and June, 2010:

cw_timeseries(phrase='united states', start_date='2009-01-01', end_date='2009-04-30', granularity='month')
#> <Sunlight data>
#>    Dimensions:   [4 X 2]
#>   count      month
#> 1  3805 2009-01-01
#> 2  3512 2009-02-01
#> 3  6018 2009-03-01
#> 4  2967 2009-04-01
dat_d <- cw_timeseries(phrase='climate change', party="D")
dat_d$party <- rep("D", nrow(dat_d))
dat_r <- cw_timeseries(phrase='climate change', party="R")
dat_r$party <- rep("R", nrow(dat_r))
dat_both <- rbind(dat_d, dat_r)
ggplot(dat_both, aes(day, count, colour=party)) +
  geom_line() +
  theme_grey(base_size=20) +


rsunlight 0.3


  • 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


  • 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


  • 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.


0.4.2 by Scott Chamberlain, 2 years ago

Report a bug at

Browse source code at

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

Documentation:   PDF Manual  

Task views:

MIT + file LICENSE license

Imports methods, utils, httr, plyr, jsonlite, stringr

Suggests knitr, testthat

Enhances ggplot2

See at CRAN