R client package for CivicFeed News API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



R client package for the CivicFeed News API. civicfeedR functions simplify the retrieval and manipulation of news data gathered from across the web by CivicFeed. More about CivicFeed here.


Install and load the civicfeedR in a few simple steps:

## install devtools if it's not already
## install civicfeedR from github
## load civicfeedR

Getting started

Before you can use the civicfeedR package, you must choose a pricing scheme to get a CivicFeed API key. Store your API key in .Renviron as the variable CF_KEY. More on how to do this here.

Package features

Look up source IDs

If you're interested in exploring news from specific sources, use lookup_id to find source IDs.

## look for ids of news sources matching the query "new york times"
lookup_id("new york times")

Get the news

To retrieve news data, make API requests using get_news.

## get 60 most popular nyt articles posted after 2018-12-01 and corresponding to the query "congress" 
news = get_news(
  q = "congress", 
  sources = 175, 
  from = "2018-12-01", 
  sort = "socialcount_last",
  pages = 2

Before calling get_news, it might be useful to check how many articles will match your get_news request, particularly if you intend to set the all argument of get_news to TRUE (i.e. you want to retrieve all articles matching your request). This ensures that you don't overrun the request limit corresponding to your CivicFeed pricing scheme, as each page of results returned counts as a separate request.

## check the number of nyt articles posted after 2018-12-01 and corresponding to the query "congress" 
  q = "congress", 
  sources = 175, 
  from = "2018-12-01"

Manipulate retrieved data

Distil useful information from the retrieved news data.

## create a tibble of the titles of the articles retrieved
## create a list of snippets from the articles retrieved
snippets_from(news, format = "list")
## create a tibble of the entities mentioned in the articles retrieved

Filter articles that mention specific entities using mentioned.

## get titles, dates published and social media shares from retrieved articles mentioning nancy pelosi 
mentioned(news, entities = "nancy pelosi", shares = TRUE)