-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
119 lines (86 loc) · 2.9 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<!-- badges: start -->
[![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)
<!-- badges: end -->
# 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))
```