-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
100 lines (67 loc) · 2.08 KB
/
README.Rmd
File metadata and controls
100 lines (67 loc) · 2.08 KB
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
---
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%"
)
```
# nytapi
<!-- badges: start -->
[](https://app.codecov.io/gh/clessn/wikirest?branch=main)
[](https://github.com/clessn/nytapi/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
The goal of nytapi is to get data from the New York Times API.
## Installation
You can install the development version of nytapi from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("clessn/nytapi")
```
## Usage
1. Get API key from [developer.nytimes.com/](https://developer.nytimes.com/)
2. Save the access token to R environ using `usethis::edit_r_environ()`
```{r eval = FALSE}
# .Renviron
NYT_KEY = "keystring"
```
3. Use key in functions
```{r eval = FALSE}
search_articles(query = "Wikipedia", key = Sys.getenv("NYT_KEY"))
```
## Examples
### Search articles
```{r}
library("nytapi")
json <- search_articles(query = "Wikipedia", key = Sys.getenv("NYT_KEY"))
# Preview of first article
article <- json[["response"]][["docs"]][[1]]
article[["abstract"]]
article[["web_url"]]
article[["snippet"]]
```
### Get most viewed articles
```{r}
json <- get_most_viewed(key = Sys.getenv("NYT_KEY"))
# Preview of first article
article <- json[["results"]][[1]]
article[["title"]]
article[["byline"]]
article[["published_date"]]
```
### Get most e-mailed articles
```{r}
json <- get_most_emailed(key = Sys.getenv("NYT_KEY"))
# Preview of first article
article <- json[["results"]][[1]]
article[["title"]]
article[["byline"]]
article[["published_date"]]
```
## Notes
For API documentation, terms of service and licensing information, see [developer.nytimes.com](https://developer.nytimes.com/).
nytapi is not afiliated with The New York Times.