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


rtimes is a collection of functions to search and acquire data from various New York Times APIs.

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/apps/register - you'll need a different key for each API.

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

I set up the functions so that you can put the key in your .Rprofile file, 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. For example, put these entries in your .Rprofile file:

options(nytimes_cg_key = "YOURKEYHERE")
options(nytimes_as_key = "YOURKEYHERE")
options(nytimes_cf_key = "YOURKEYHERE")
options(nytimes_geo_key = "YOURKEYHERE")

From CRAN

install.packages("rtimes")

Development version from GitHub

install.packages("devtools")
devtools::install_github("ropengov/rtimes")
library("rtimes")
out <- cg_rollcallvote(congress_no = 105, chamber = 'house', session_no = 2, rollcall_no = 38)
out$votes
#> Source: local data frame [4 x 6]
#> 
#>     yes    no present not_voting majority_position       label
#>   (chr) (chr)   (chr)      (chr)             (chr)       (chr)
#> 1   194     0       0          9               Yes  democratic
#> 2   219     1       0          6               Yes  republican
#> 3     1     0       0          0                NA independent
#> 4   414     1       0         15                NA       total

Article Search API

out <- as_search(q = "bailout", begin_date = "20081001", end_date = '20081201')
out$data[1:2]
#> [[1]]
#> <NYTimes article>Toxic Bailout
#>   Type: News
#>   Published: 2008-10-05T00:00:00Z
#>   Word count: 913
#>   URL: http://www.nytimes.com/2008/10/05/magazine/05wwln-safire-t.html
#>   Snippet: How can you be naked wearing shorts?
#> 
#> [[2]]
#> <NYTimes article>Bailout narratives
#>   Type: Blog
#>   Published: 2008-10-01T10:08:26Z
#>   Word count: 440
#>   URL: http://krugman.blogs.nytimes.com/2008/10/01/bailout-narratives/
#>   Snippet: There seem to be two prevailing narratives about the bailout plan(s). Both have elements of truth, but are fundamentally wrong. One narrative is that of the Wise Men and the Destructive Yahoos. According to this narrative, men who Understand What...
res <- cf_candidate_details(campaign_cycle = 2008, fec_id = 'P80003338')
res$data
#> Source: local data frame [2 x 19]
#> 
#>   cycle.id cycle.fecid                       cycle.name cycle.party
#>      (chr)       (chr)                            (chr)       (chr)
#> 1     2896   P80003338 /BIDEN, JOSEPH R., OBAMA, BARACK         DEM
#> 2    50162   P80003338 /BIDEN, JOSEPH R., OBAMA, BARACK         DEM
#> Variables not shown: cycle.status (chr), cycle.address_one (chr),
#>   cycle.address_two (chr), cycle.city (chr), cycle.state (chr), cycle.zip
#>   (chr), cycle.fec_committee_id (chr), cycle.cycle (chr), cycle.district
#>   (chr), cycle.office_state (chr), cycle.cand_status (chr), cycle.branch
#>   (chr), relative_uri (chr), cycle.created_at (chr), cycle.updated_at
#>   (chr)
geo_search(elevation = '2000_3000', feature_class = 'P')
#> $copyright
#> [1] "Copyright (c) 2015 The New York Times Company.  All Rights Reserved."
#> 
#> $meta
#>   status num_results
#> 1     OK         100
#> 
#> $data
#> Source: local data frame [100 x 27]
#> 
#>    concept_id          concept_name geocode_id geoname_id          name
#>         (chr)                 (chr)      (int)      (int)         (chr)
#> 1       26660   Los Angeles (Calif)        132    5368361   Los Angeles
#> 2       27500      New Orleans (La)        148    4335045   New Orleans
#> 3       24084         Chicago (Ill)        160    4887398       Chicago
#> 4       27988        Paris (France)        196    2988507         Paris
#> 5       28808 San Francisco (Calif)        212    5391959 San Francisco
#> 6       23464         Boston (Mass)        240    4930956        Boston
#> 7       25760             Hong Kong        288    1819729     Hong Kong
#> 8       26636      London (England)        308    2643743        London
#> 9       23196       Beijing (China)        312    1816670       Beijing
#> 10      24576        Detroit (Mich)        328    4990729       Detroit
#> ..        ...                   ...        ...        ...           ...
#> Variables not shown: latitude (dbl), longitude (dbl), elevation (int),
#>   population (int), country_code (chr), country_name (chr), admin_code1
#>   (chr), admin_code2 (chr), admin_code3 (chr), admin_code4 (chr),
#>   admin_name1 (chr), admin_name2 (chr), admin_name3 (chr), admin_name4
#>   (chr), 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)
  • 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.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, 3 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