-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.Rmd
87 lines (71 loc) · 2.32 KB
/
index.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
<!-- badges go here -->
[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/JohnCoene)
[![Travis build status](https://travis-ci.org/news-r/guardian.svg?branch=master)](https://travis-ci.org/news-r/guardian)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/news-r/guardian?branch=master&svg=true)](https://ci.appveyor.com/project/news-r/guardian)
<!-- badges: end -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
warning = FALSE,
collapse = TRUE,
comment = "#>"
)
library(htmltools)
```
```{r, echo=FALSE}
br()
br()
div(
class = "row",
div(
class = "col-md-4",
img(
src = "logo.png",
class = "img-responsive responsive-img"
)
),
div(
class = "col-md-8",
p(
"Access over 2 million pieces of content from The Guardian."
),
p(
tags$a(
tags$i(class = "fa fa-code"),
class = "btn btn-primary",
href = "reference/index.html",
style = "margin-bottom: 5px;",
"Reference"
),
tags$a(
tags$i(class = "fa fa-github"),
class = "btn btn-default",
href = "https://github.com/news-r/guardian",
style = "margin-bottom: 5px;",
"Repository"
)
)
)
)
```
## Installation
You can install the package with `remotes` from Github, see [changes](news/index.html).
```{r, eval=FALSE}
# install.packages("remotes")
remotes::install_github("news-r/pkg") # github
```
## Setup
To get started, You need a [free API key](https://open-platform.theguardian.com/access/). Then either specify the aforementioned key using `guardian_key` or specify it as environment variable (likely in your .Renviron) as `GUARDIAN_API_KEY`.
```r
guardian_key("xxXXxxXx")
```
## Example
The package revolves around the following principle, first create your API calls then execute them with `gd_call`. This is because the package is built upon the [async package](https://github.com/r-lib/async) which lets you execute API calls asynchonously: the (free) developer plan allows you to do up to 12 calls per second.
Below we look for 15 pages of articles on "Brexit".
```{r}
library(guardian)
# search for brexit articles
(to_search <- gd_search("brexit", pages = 15))
# actually execute 15 calls (1 per page)
results <- gd_call(to_search)
head(results)
```