README.md

Travis build status AppVeyor build status

nytimes

The goal of nytimes is to integrate all of the New York Times API with R.

Installation

#install.packages("remotes")
remotes::install_github("news-r/nytimes")

APIs

Setup

First, create an account to obtain an API key. Then either specify the aforementioned key using nytimes_key or specify it as environment variable (likely in your .Renviron) as NYTIMES_API_KEY.

library(nytimes)

nytimes_key("xXxxX")

Examples

The archive API.

library(nytimes)

# get all articles from January first 2018
archive <- ny_archive(2018, 1)
#> ℹ 6903 results returned

The article search API.

# get all articles on Obama that have been published in the last 3 days, get three pages of results
obama <- ny_search("Obama", since = Sys.Date() - 3, pages = 3)
#> ℹ 49 results available
#> 
  downloading [=======================================] 100%

The books API

# get data on a random book
books <- ny_book_names()
#> ℹ 55 results returned
list <- ny_book_list(sample(books$list_name_encoded, 1))
#> ℹ 10 results returned

The most popular API

# get most viewed articles in the last 7 days
viewed <- ny_popular_viewed(7)
#> ℹ 1716 results returned

The movie review API

# get 2 pages of movie reviews on war
reviews <- ny_movie_search("war", pages = 2)
#> ⚠ More results available

The semantic API

# get 2 pages of movie reviews on war
concepts <- ny_semantic_search("war")
#> ℹ 500 results available
#> ⚠ More results available

Times tags API

ny_tags("Trump", max = 6)
#> [1] "Trump, Donald J (Per)"    "Trump Organization (Org)"
#> [3] "Trump, Ivanka (Per)"      "Trump, Melania (Per)"    
#> [5] "Trump, Donald J Jr (Per)" "Wallace, George C (Per)"

Top stories API

business <- ny_stories("business")

Times wire API

sections <- ny_wire_section_list()
wires <- ny_wire_source(sample(sections$section, 1))
#> ℹ 3298 results available


news-r/nytimes documentation built on Feb. 28, 2020, 4:49 a.m.