An open API service indexing awesome lists of open source software.

https://github.com/news-r/nytimes

🍎 R wrapper to New York Times APIs
https://github.com/news-r/nytimes

api news nytimes r rstats

Last synced: 24 days ago
JSON representation

🍎 R wrapper to New York Times APIs

Awesome Lists containing this project

README

        

---
output: github_document
---

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

[![Travis build status](https://travis-ci.org/news-r/nytimes.svg?branch=master)](https://travis-ci.org/news-r/nytimes)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/news-r/nytimes?branch=master&svg=true)](https://ci.appveyor.com/project/news-r/nytimes)

# nytimes

The goal of `nytimes` is to integrate all of the [New York Times API](https://developer.nytimes.com) with R.

## Installation

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

## APIs

- [x] [Archive](https://developer.nytimes.com/docs/archive-product/1/overview)
- [x] [Article Search](https://developer.nytimes.com/docs/articlesearch-product/1/overview)
- [x] [Books](https://developer.nytimes.com/docs/books-product/1/overview)
- [x] [Geo](https://developer.nytimes.com/docs/geo-product/1/overview)
- [x] [Most Popular](https://developer.nytimes.com/docs/most-popular-product/1/overview)
- [x] [Movie Reviews](https://developer.nytimes.com/docs/movie-reviews-api/1/overview)
- [x] [Semantic](https://developer.nytimes.com/docs/semantic-api-product/1/overview)
- [x] [Times Tags](https://developer.nytimes.com/docs/timestags-product/1/overview)
- [x] [Times Wire](https://developer.nytimes.com/docs/timeswire-product/1/overview)
- [x] [Top Stories](https://developer.nytimes.com/docs/top-stories-product/1/overview)

## Setup

First, [create an account](https://developer.nytimes.com) 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`.

```r
library(nytimes)

nytimes_key("xXxxX")
```

## Examples

The archive API.

```{r}
library(nytimes)

# get all articles from January first 2018
archive <- ny_archive(2018, 1)
```

The article search API.

```{r}
# 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

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

The most popular API

```{r}
# get most viewed articles in the last 7 days
viewed <- ny_popular_viewed(7)
```

The movie review API

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

The semantic API

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

Times tags API

```{r}
ny_tags("Trump", max = 6)
```

Top stories API

```r
business <- ny_stories("business")
```

Times wire API

```{r}
sections <- ny_wire_section_list()
wires <- ny_wire_source(sample(sections$section, 1))
```