Client for New York Times 'APIs'

Interface to Congress, Campaign Finance, Article Search, and Geographic 'APIs' from the New York Times (< http://developer.nytimes.com/>) and 'ProPublica' (< https://www.propublica.org/datastore/apis>). This client covers a subset of the New York Times and 'ProPublica' 'APIs'.


Build Status codecov.io rstudio mirror downloads cran version

rtimes is a collection of functions to search and acquire data from various New York Times APIs, some of which now live at Propublica.

Functions in rtimes that wrap these APIs are prefixed by two letter acronyms fo reach API + the function name itself, e.g.: cg + fxn

Please get your own API keys at http://developer.nytimes.com/ for as and geo functions, and for cg and cf functions by emailing Propublica at [email protected].

You'll need a different key for each API of the Nytimes APIs, but only one key for the Propublica APIs

Data from the New York Times API is provided by The New York Times.

NYT API

And data from Propublica API is provided by Propublica

Propublica API

I set up the functions so that you can put the key in your .Renviron file (or any file on your system that holds env vars), which will be called on startup of R, and then you don't have to enter your API key for each run of a function. Use the following env var names

  • NYTIMES_GEO_KEY - for geo methods
  • NYTIMES_AS_KEY - for as methods
  • PROPUBLICA_API_KEY - for cg and cf methods

From CRAN

install.packages("rtimes")

Development version from GitHub

install.packages("devtools")
devtools::install_github("ropengov/rtimes")
library("rtimes")

Congress API

out <- cg_rollcallvote(congress_no = 105, chamber = 'house', session_no = 2, rollcall_no = 38)
out$votes
#>      category yes no present not_voting majority_position
#> 1  democratic 194  0       0          9               Yes
#> 2  republican 219  1       0          6               Yes
#> 3 independent   1  0       0          0              <NA>
#> 4       total 414  1       0         15              <NA>

Article Search API

x <- as_search(q = "bailout", begin_date = "20081001", end_date = '20081201')
x$data
#> # A tibble: 10 x 19
#>                                                                        web_url
#>  *                                                                       <chr>
#>  1 https://dealbook.nytimes.com/2008/10/17/nader-displays-new-fervor-on-the-ba
#>  2              https://dealbook.nytimes.com/2008/10/07/its-the-economy-redux/
#>  3                https://www.nytimes.com/2008/12/01/opinion/l01citigroup.html
#>  4             https://www.nytimes.com/2008/12/01/business/economy/01auto.html
#>  5                    https://www.nytimes.com/2008/12/01/business/01tanta.html
#>  6                      https://www.nytimes.com/2008/12/01/business/01uaw.html
#>  7         https://www.nytimes.com/2008/12/01/business/economy/01stimulus.html
#>  8                      https://www.nytimes.com/2008/11/30/opinion/30sun1.html
#>  9                    https://www.nytimes.com/2008/11/30/opinion/30boskin.html
#> 10                   https://www.nytimes.com/2008/11/30/business/30dealer.html
#> # ... with 18 more variables: snippet <chr>, abstract <chr>, source <chr>,
#> #   multimedia <list>, keywords <list>, pub_date <chr>,
#> #   document_type <chr>, section_name <chr>, type_of_material <chr>,
#> #   `_id` <chr>, word_count <int>, score <dbl>, print_page <chr>,
#> #   new_desk <chr>, headline.main <chr>, headline.kicker <chr>,
#> #   headline.print_headline <chr>, byline.original <chr>

Campaign Finance API

cf_candidate_details(campaign_cycle = 2008, fec_id = 'P80003338')
#> $status
#> [1] "OK"
#> 
#> $copyright
#> [1] "Copyright (c) 2017 ProPublica Inc. All Rights Reserved."
#> 
#> $data
#> # A tibble: 1 x 24
#>          id          name party
#>       <chr>         <chr> <chr>
#> 1 P80003338 OBAMA, BARACK   DEM
#> # ... with 21 more variables: fec_uri <chr>, committee <chr>,
#> #   mailing_address <chr>, mailing_city <chr>, mailing_state <chr>,
#> #   mailing_zip <chr>, status <chr>, total_receipts <chr>,
#> #   total_from_individuals <chr>, total_from_pacs <chr>,
#> #   total_contributions <chr>, candidate_loans <chr>,
#> #   total_disbursements <chr>, begin_cash <chr>, end_cash <chr>,
#> #   total_refunds <chr>, debts_owed <chr>, date_coverage_from <chr>,
#> #   date_coverage_to <chr>, independent_expenditures <chr>,
#> #   coordinated_expenditures <chr>

Geographic API

geo_search(country_code = "US")
#> $copyright
#> [1] "Copyright (c) 2015 The New York Times Company.  All Rights Reserved."
#> 
#> $meta
#>   status num_results
#> 1     OK         100
#> 
#> $data
#> # A tibble: 100 x 27
#>    concept_id              concept_name geocode_id geoname_id
#>  *      <chr>                     <chr>      <int>      <int>
#>  1      22456             Abilene (Tex)       4500    4669635
#>  2      22460             Abingdon (Va)       7752    4743815
#>  3      22480 Acadia National Park (Me)       4504    4956449
#>  4      22508 Adirondack Mountains (NY)       1488    5106772
#>  5      22548                   Alabama        364    4829764
#>  6      22556                    Alaska        292    5879092
#>  7      22564               Albany (NY)        464    5106834
#>  8      22572          Albuquerque (NM)       1596    5454711
#>  9      22576  Alcatraz (San Francisco)       7772    5322901
#> 10      22580           Alexandria (Va)       4008    4744091
#> # ... with 90 more rows, and 23 more variables: name <chr>,
#> #   latitude <dbl>, longitude <dbl>, elevation <int>, population <int>,
#> #   country_code <chr>, country_name <chr>, admin_code1 <chr>,
#> #   admin_code2 <chr>, admin_code3 <lgl>, admin_code4 <lgl>,
#> #   admin_name1 <chr>, admin_name2 <chr>, admin_name3 <lgl>,
#> #   admin_name4 <lgl>, feature_class <chr>, feature_code <chr>,
#> #   feature_code_name <chr>, time_zone_id <chr>, dst_offset <dbl>,
#> #   gmt_offset <dbl>, geocodes_created <chr>, geocodes_updated <chr>

Meta

  • 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.
  • Maintainer: Scott Chamberlain
  • License: MIT
  • Report any problems in the Issues Tracker, or just fork and submit changes, etc.

News

rtimes 0.5.0

MINOR IMPROVEMENTS

  • Now using crul as the HTTP client under the hood (#16)
  • Updated docs with links to new API docs for all 4 APIs (#17)
  • Moved to using markdown docs - though all those in templated man/ still in old style (#18)

rtimes 0.4.0

NEW FEATURES

  • as_search gains new parameter all_results to internally paginate to get all results. In addition, user can optionally have the function attempt to flatten completely the output data.frame, but sometimes may fail so isn't turned on by default (#15)

MINOR IMPROVEMENTS

  • Now API keys have to be stored as environment variables instead of options (#12)
  • Campaign and Congress APIs moved to Propublica. Updated base URLs, etc for the move, but many routes still not covered. (#13)
  • Replace dplyr::rbind_all with dplyr::bind_rows (#14)

rtimes 0.3.0

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("rtimes")

0.5.0 by Scott Chamberlain, 10 months ago


https://github.com/ropengov/rtimes


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


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


Authors: Scott Chamberlain [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports utils, crul, jsonlite, dplyr, tibble, data.table

Suggests roxygen2, knitr, testthat, lubridate, ggplot2, scales, grid


See at CRAN