Skip to content

An R package for downloading data from the Commons and Lords Votes API

Notifications You must be signed in to change notification settings

houseofcommonslibrary/clvotes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clvotes

clvotes is an R package for downloading data from the UK Parliament's Commons Votes API and Lords Votes API. This package has been developed principally to support work on Parliamentary data in the House of Commons Library but it may be useful to other researchers working with this data. This package is still in active development and the API may evolve over time.

Overview

The package provides sets of functions for retrieving data from different endpoints of the respective votes API and returning the data as a tibble. The package currently provides functions to download data from the main Commons and Lords Votes endpoints, but new functions may be added to extract data from other endpoints in future. The package does not aim to exhaustively expose every possible API parameter for a given endpoint, but is focussed on downloading key datasets than can be further explored, transformed and combined with other data in R. To help with using parts of the API that are not explicitly covered, the package also provides some lower level functions that allow you to retrieve data from any API endpoint URL as native R data structures.

Installation

Install from Github with using remotes.

install.packages("remotes")
remotes::install_github("houseofcommonslibrary/clvotes")

Commons divisions

Some Commons functions have an optional arguments called from_date, to_date and on_date which can be used to filter the rows returned based on the date of a division. The on_date argument is a convenience that sets the from_date and to_date to the same given date. The on_date has priority: if the on_date is set, the from_date and to_date are ignored. The values for these arguments can be either a Date or a string specifying a date in ISO 8601 format ("YYYY-MM-DD").


clvotes::fetch_commons_divisions_all(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about each Commons division, with one row per division.

This dataframe contains summary details for each division, such as the division date, title, the number of MPs who voted "Aye" and the number of MPs who voted "No".


clvotes::fetch_commons_divisions_evel(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about each EVEL Commons division, with one row per EVEL division.

This dataframe contains summary details for each EVEL division, such as the division date, title, EVEL type, the number of MPs who voted "Aye" and the number of MPs who voted "No".


clvotes::fetch_commons_divisions_deferred(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about each deferred Commons division, with one row per deferred division.

This dataframe contains summary details for each deferred division, such as the division date, title, the number of MPs who voted "Aye" and the number of MPs who voted "No".


clvotes::fetch_commons_divisions_tellers(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about each Commons division teller, with one row per division teller.

This dataframe contains summary details for each division teller, such as the division date, title, the division lobby of the teller, the teller name and teller party. Divisions with zero tellers are ignored.


clvotes::fetch_commons_divisions_remote(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about each remote Commons division, with one row per remote division.

This dataframe contains summary details for each remote division, such as the division date, title, the number of MPs who voted "Aye" and the number of MPs who voted "No".


clvotes::fetch_commons_divisions_votes(division_id)

Fetch a dataframe of key details about how each MP voted in a Commons division, with one row per MP vote.

This dataframe contains summary details for a division, such as the division date, title, the vote direction of an MP, the MP name, and proxy used (if any).


clvotes::fetch_commons_divisions_party(division_id)

Fetch a dataframe of key details about how each party voted in a Commons division, with one row per party vote direction.

This dataframe contains summary details for a division, such as the division date, title, party and each vote direction.


clvotes::fetch_commons_divisions_members(member_mnis_id, from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about the division voting record of an MP, with one row per division.

This dataframe contains summary details on the voting record of an MP, such as the division date, title, whether the MP voted "Aye" and whether the MP was a teller.


Lords divisions

Some Lords functions have an optional arguments called from_date, to_date and on_date which can be used to filter the rows returned based on the date of a division. The on_date argument is a convenience that sets the from_date and to_date to the same given date. The on_date has priority: if the on_date is set, the from_date and to_date are ignored. The values for these arguments can be either a Date or a string specifying a date in ISO 8601 format ("YYYY-MM-DD").


clvotes::fetch_lords_divisions_all(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about each Lords division, with one row per division.

This dataframe contains summary details for each division, such as the division date, title, the number of Lords who voted "Content" and the number of MPs who voted "Not content".


clvotes::fetch_lords_divisions_tellers(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about each Lords division teller, with one row per division teller.

This dataframe contains summary details for each division teller, such as the division date, title, the division lobby of the teller, the teller name and teller party. Divisions with zero tellers are ignored.


clvotes::fetch_lords_divisions_remote(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about each remote Lords division, with one row per remote division.

This dataframe contains summary details for each remote division, such as the division date, title, the number of Lords who voted "Content" and the number of MPs who voted "Not content".


clvotes::fetch_lords_divisions_votes(division_id)

Fetch a dataframe of key details about how each Lord voted in a Lords division, with one row per Lord vote.

This dataframe contains summary details for a division, such as the division date, title, the vote direction of a Lord, the Lord name, and party.


clvotes::fetch_lords_divisions_party(division_id)

Fetch a dataframe of key details about how each party voted in a Lords division, with one row per party vote direction.

This dataframe contains summary details for a division, such as the division date, title, party and each vote direction.


clvotes::fetch_lords_divisions_members(member_mnis_id, from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of key details about the division voting record of aLord, with one row per division.

This dataframe contains summary details on the voting record of a Lord, such as the division date, title, whether the Lord voted "Content" and whether the Lord was a teller.


Raw queries

Functions to download the 'raw' equivalents of fetch_commons_divisions_all and fetch_lords_divisions_all. These functions convert the JSON returned from the relevant API call into a Tibble with column names cleaned. No sub-selecting of columns and variable names occurs.


clvotes::fetch_commons_divisions_all_raw(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of all data associated with a division from the Commons Votes API endpoint /data/divisions.json/search. No cleaning of the data occurs and so columns may be duplicated and contain nested lists or dataframes. This function is intended for users to develop further queries not provided in the core functions of this package.


clvotes::fetch_lords_divisions_all_raw(from_date = NA, to_date = NA, on_date = NA)

Fetch a dataframe of all data associated with a division from the Lords Votes API endpoint /data/Divisions/search. No cleaning of the data occurs and so columns may be duplicated and contain nested lists or dataframes. This function is intended for users to develop further queries not provided in the core functions of this package.

About

An R package for downloading data from the Commons and Lords Votes API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages