Package 'rdian'

Title: Client Library for The Guardian
Description: A client library for 'The Guardian' (https://www.guardian.com/) and their API, this package allows users to search for Guardian articles and retrieve both the content and metadata.
Authors: Oliver Keyes
Maintainer: Oliver Keyes <[email protected]>
License: MIT + file LICENSE
Version: 0.1.1
Built: 2024-11-22 04:06:09 UTC
Source: https://github.com/ironholds/rdian

Help Index


AND and OR operators for Guardian filters and queries.

Description

guardian_and and guardian_or provide (respectively) the AND and OR logical operators. If you pass them your query terms, it passes them back either separated (so that the Guardian API knows to consider a match to any one term a match) or grouped (so that the API only matches if every term appears).

Usage

guardian_and(...)

guardian_or(...)

Arguments

...

a vector of terms (or several vector of terms)

Value

a single string containing the terms, separated by the AND (,) or OR (|) separators used by the Guardian API.

Examples

# Simple AND example
guardian_and("sausage", "mash")

# With ORs
guardian_or("sausage", "mash")

Search Guardian Content

Description

guardian_content lets you directly search The Guardian for content, including support for conditional searches, date-range based filtering, and section or tag based filtering.

Usage

guardian_content(api_key, query, from = NULL, to = NULL, section = NULL,
  reference = NULL, reference_type = NULL, tags = NULL, rights = NULL,
  ids = NULL, production_office = NULL, page = NULL, page_size = 50,
  fields = NULL, collapse = TRUE, ...)

Arguments

api_key

A key to the Guardian API, which can be obtained here.

query

Your search query. This can contain operators (sausage AND mash) or phrases ("sausage & mash"); by default, searches work as an OR, looking for the presence of any one individual word in the query.

from

the date to limit by. If set, the search will only cover data written after this date. Optional (NULL) by default. Can be set in conjunction with to.

to

Another date to limit by. If set, the search will only cover data written before this date. Optional (NULL) by default. Can be set in conjunction with from.

section

the section, or sections, of The Guardian that you want to limit the search to. Multiple sections may be concatenated together using boolean operators; see guardian_and and guardian_or.

reference

the references to limit the search to; only articles that include those references (and meet other conditions) will be returned. Also accepts boolean operators.

reference_type

the type of reference (such as isbn). Also accepts boolean operators.

tags

the tags to limit the search to; only articles that contain these tags will be returned. Also accepts boolean operators.

rights

limit a search to content with these rights (syndicatable content, for example). Options are syndicatable and subscription-database. Does not accept boolean operators.

ids

limit a search to content with these IDs, an ID being the standard URL fragment after guardian.com ( or co.uk, or...). Does not accept boolean operators.

production_office

the production office(s) to limit to, such as "aus". Accepts boolean operators.

page

a particular page of results to return. Useful when returning multiple sets of data with the same query; you can repeat the query, incrementing the value in page.

page_size

the maximum number of items to return; anywhere between 1 and 50. Set to 50 by default.

fields

additional fields to include in the returned data (when available). Possible values (which should appear in a vector) appear here.

collapse

whether to collapse the actual content into a data.frame. Set to TRUE by default.

...

further arguments to pass to httr's GET.

See Also

guardian_tags to retrieve metadata about tags.

Examples

# Simple example
## Not run: 
result <- guardian_content("test", "debate AND economy")

## End(Not run)

Search Guardian Editions

Description

guardian_editions lets you directly search The Guardian for metadata about their editions - country-specific (or international) standard releases for their website's content.

Usage

guardian_editions(api_key, query, ...)

Arguments

api_key

A key to the Guardian API, which can be obtained here.

query

Your search query.

...

further arguments to pass to httr's GET.

See Also

guardian_sections for retrieving sections, another category of content.

Examples

## Not run: 
# Simple example
uk_edition_data <- guardian_editions("test", "uk")

## End(Not run)

Search Guardian Sections

Description

guardian_sections lets you directly search The Guardian for metadata about sections - individual categories of content, such as world or US news.

Usage

guardian_sections(api_key, query, ...)

Arguments

api_key

A key to the Guardian API, which can be obtained here.

query

Your search query. This can contain operators (sausage AND mash) or phrases ("sausage & mash"); by default, searches work as an OR, looking for the presence of any one individual word in the query.

...

further arguments to pass to httr's GET.

See Also

guardian_tags for retrieving tags, another class of content metadata.

Examples

## Not run: 
# Simple example
business_sections <- guardian_sections("test", "business")

## End(Not run)

Search Guardian Tags

Description

guardian_tags lets you directly search The Guardian for their tags - metadata used to classify content.

Usage

guardian_tags(api_key, query, section = NULL, reference = NULL,
  reference_type = NULL, page = NULL, page_size = 50, ...)

Arguments

api_key

A key to the Guardian API, which can be obtained here.

query

Your search query. This can contain operators (sausage AND mash) or phrases ("sausage & mash"); by default, searches work as an OR, looking for the presence of any one individual word in the query.

section

the section, or sections, of The Guardian that you want to limit the search to. Multiple sections may be concatenated together using boolean operators; see guardian_and and guardian_and.

reference

the references to limit the search to; only tags that include those references (and meet other conditions) will be returned. Also accepts boolean operators.

reference_type

the type of reference (such as isbn). Also accepts boolean operators.

page

a particular page of results to return. Useful when returning multiple sets of data with the same query; you can repeat the query, incrementing the value in page.

page_size

the maximum number of items to return; anywhere between 1 and 50. Set to 50 by default.

...

further arguments to pass to httr's GET.

See Also

guardian_content.

Examples

## Not run: 
# Simple example
results <- guardian_tags("test", "green")

## End(Not run)

Modern API client for The Guardian

Description

This package provides a modern (httr/curl/jsonlite-based) API client for The Guardian (https://guardian.co.uk), allowing useRs to retrieve content and content metadata.