Giter Club home page Giter Club logo

pollstr's Introduction

CRAN Version Downloads Build Status

pollstR: An R Client for the HuffPost Pollster API

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:

pollster_polls()

Get a specific poll by its identifier

pollster_polls_slug("gallup-26892")

Return a list of questions:

pollster_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:

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

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

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

Return a list of charts

pollster_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

pollster_tags()

Pagination

Several of the Pollster API methods are paginated, with limits the the number or results returned with each request. The paginated methods are ones with a cursor argument. The function pollster_iter iterates over multiple pages of API results,

pollster_iter(pollster_charts, .max_pages = 2)

There are wrappers for the paginated API methods:

pollster_charts_iter(.max_pages = 2)

pollster_polls_iter(.max_pages = 2)

pollster_questions_iter(.max_pages = 2)

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.

pollstr's People

Contributors

jrnold avatar leeper avatar dlinzer avatar olliemcdonald avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.