Say Thanks! Travis build status AppVeyor build status

knitr::opts_chunk$set(
  warning = FALSE,
  collapse = TRUE,
  comment = "#>"
)

library(htmltools)
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.

# install.packages("remotes")
remotes::install_github("news-r/pkg") # github

Setup

To get started, You need a free API key. Then either specify the aforementioned key using guardian_key or specify it as environment variable (likely in your .Renviron) as GUARDIAN_API_KEY.

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 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".

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)


news-r/guardian documentation built on July 16, 2019, 3:25 a.m.