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
- Host: GitHub
- URL: https://github.com/news-r/nytimes
- Owner: news-r
- License: other
- Created: 2019-05-31T21:33:22.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-09T00:03:24.000Z (6 months ago)
- Last Synced: 2025-03-20T16:51:17.652Z (about 1 month ago)
- Topics: api, news, nytimes, r, rstats
- Language: R
- Homepage:
- Size: 41 KB
- Stars: 16
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - news-r/nytimes - 🍎 R wrapper to New York Times APIs (R)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```[](https://travis-ci.org/news-r/nytimes)
[](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))
```