-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME.Rmd
60 lines (45 loc) · 1.08 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
## News API
- R client for newsAPIorg
## API key
- Go to [newsapi.org](https://newsapi.org) and register to get an API
key.
- Save the key as an environment variable
```{r, eval=FALSE}
## my obscured key
NEWSAPI_KEY <- "4345e85e8ae1427480xxxxxxxxxxxxxx"
## save to .Renviron file
cat(
paste0("NEWSAPI_KEY=", NEWSAPI_KEY),
append = TRUE,
fill = TRUE,
file = file.path("~", ".Renviron")
)
```
## Install
- Install from Github
```{r, eval=FALSE}
## install script
if (!"devtools" %in% installed.packages()) {
install.packages("devtools")
}
devtools::install_github("mkearney/newsAPI")
## load package
library(newsAPI)
```
## Demo
- Get all available news sources
```{r}
## get all english language news sources (made available by newsapi.org)
src <- get_sources(language = "en")
## preview data
print(src, width = 500)
```
- Pass news source names (IDs) to `get_articles` function
```{r}
## apply get_articles function to each news source
df <- lapply(src$id, get_articles)
## collapse into single data frame
df <- do.call("rbind", df)
## preview data
print(df, width = 500)
```