CRAN Version DownloadsBuild Status

The pollster package provides an R client for the Huffpost Pollster API. Huffpost Pollster tracks and aggregates US public polls on elections and political opinions. The API provides programmatic access to the data.

This package is part of the ROpenGov project.

Install

You can install the stable version on CRAN:

install.packages('pollstR', dependencies = TRUE)

To install the latest version:

library("devtools")
install_github("rOpenGov/pollstR")

Usage

library("pollstR")

The function pollster_api provides a thin wrapper to the make requests of the API:

pollster_api("polls")

For more information, see full documentation for the API.

API Methods

There is also a function for each API method.

Return a list of polls:

Get a specific poll by its identifier

pollster_polls_slug("gallup-26892")

Return a list of questions:

Return a specific question by its identifier

pollster_questions_slug("17-VA-Gov-GE-SvP")

Return a table with one row of response values per poll question + subpopulation of a given question and columns are responses:

Return a table with one row of response values per poll question + subpopulation + response of a given question

Return a list of charts

Return a chart

pollster_charts_slug("2016-general-election-trump-vs-clinton")

Return a table with one row per poll for the chart

pollster_charts_polls("2016-general-election-trump-vs-clinton")

Return a table with the trendline for a chart

pollster_charts_trendlines("2016-general-election-trump-vs-clinton")

Return a list of tags used in charts, polls, and questions

Bugs

If you encounter an error when using one of the functions it is likely that there was an error in converting the data as returned by the API into data structures more usable in R. This may happen when the Huffpost Pollster API changes, and pollstR has not been updated yet.

  1. Install the latest version of pollstR from github and see if the bug has been fixed.
  2. Open a new issue on github

License

The package is released under GPL-2 and the API data it accesses is released under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.