knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

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)

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)

The books API

# get data on a random book
books <- ny_book_names()
list <- ny_book_list(sample(books$list_name_encoded, 1))

The most popular API

# get most viewed articles in the last 7 days
viewed <- ny_popular_viewed(7)

The movie review API

# get 2 pages of movie reviews on war
reviews <- ny_movie_search("war", pages = 2)

The semantic API

# get 2 pages of movie reviews on war
concepts <- ny_semantic_search("war")

Times tags API

ny_tags("Trump", max = 6)

Top stories API

business <- ny_stories("business")

Times wire API

sections <- ny_wire_section_list()
wires <- ny_wire_source(sample(sections$section, 1))


news-r/nytimes documentation built on Sept. 7, 2024, 1:02 a.m.