mnis
is an R package to pull data from the UK parliament through the Members' Name Information Service API, with the ability to tidy that data into object classes that are easy to work with in R. It emphasises simplicity and ease of use, so that users unfamiliar with APIs can easily retrieve large volumes of high quality data. The Members' Name Information Service API does not require registration or a token, and is very generous with the number of requests allowed (it is unclear what limits are applied to the API, but I have yet to hit the limit, aside from custom requests using mnis_base()
.)
mnis
is for researchers, journalists and developers who follow the UK parliament for work, pleasure or some combination thereof. It has a sister package called hansard
that retrieves data from a different API, and while there is some overlap in function between the two packages, mnis
is focused on retrieving data on individual MPs and Peers, government departments, cabinet and shadow cabinet positions, other parliamentary and political roles, and parliamentary reference data.
All functions requests data in JSON format and parse it to a tibble, except for mnis_constituency_results()
which returns a list (with constituency details) and a tibble (with constituency election results).
Functions are divided into four main types:
General Functions
Reference Functions
Additional Information Functions
Fixed Scope Functions
There is also the mnis_base()
function that allows for fully flexibility in all API requests, by allowing you to fully specify the URL you want to call data from.
mnis
install.packages("mnis")
install.packages("devtools") devtools::install_github("EvanOdell/mnis")
mnis
library(mnis)
mnis
All mnis
functions contain two parameters, tidy
and tidy_style
:
tidy
is a logical parameter accepting either TRUE or FALSE, defaulting to TRUE. If TRUE, mnis
will fix variable names, which by default contain non alpha-numeric characters and appear to use an inconsistent/idiosyncratic naming convention, at least by the standards of the various naming conventions used in R. Dates and datetimes are converted to POSIXct class. The default variable names are unnecessarily lengthy and repeat the same piece of information several times in a row and contain non-alphanumeric characters. tidy
fixes this, and defaults to TRUE, so you won't have to deal with the clunky and over-complicated default variable names unless you really want to. It transforms names like "Members.Member.BasicDetails.Gender"
into "gender"
.
The naming convention for variables used if tidy
==TRUE is indicated by tidy_style
. tidy_style
accepts one of "snake_case"
, "camelCase"
and "period.case"
, defaulting to "snake_case"
. All variable names will be converted to match the given naming convention.
The mnis_base()
function accepts requests to the mnis API. The full list of request options is available on the mnis website: http://data.parliament.uk/membersdataplatform/memberquery.aspx
A series of functions to return reference data. This data is useful for providing parameters for other function calls. These functions do not accept any arguments.
ref_address_types()
ref_answering_bodies()
ref_areas()
ref_area_types()
ref_biography_categories()
ref_cabinets()
ref_committees()
ref_committee_types()
ref_constituencies()
ref_constituency_areas()
ref_constituency_types()
ref_countries()
ref_departments()
ref_disqualification_types()
ref_elections()
ref_election_types()
ref_end_reasons()
ref_experience_types()
ref_government_post_departments()
ref_government_posts()
ref_government_ranks()
ref_honourary_prefixes()
ref_honour_lists()
ref_honours()
ref_interest_categories()
ref_lords_membership_types()
ref_lords_ranks()
ref_opposition_post_departments()
ref_opposition_posts()
ref_opposition_ranks()
ref_other_parliaments()
ref_parliamentary_posts()
ref_parliamentary_ranks()
ref_parliament_types()
ref_parties()
ref_party_sub_types()
ref_photo_outputs()
ref_statuses()
ref_titles()
library(mnis) x <- ref_titles(tidy = FALSE) x
With the tidy
parameter
library(mnis) x <- ref_titles(tidy = TRUE) x
mnis_additional()
mnis_addresses()
mnis_basic_details()
mnis_biography_entries()
mnis_committees()
mnis_constituencies()
mnis_elections_contested
mnis_experiences()
mnis_government_posts()
mnis_honours()
mnis_house_memberships()
mnis_interests()
mnis_known_as()
mnis_maiden_speeches()
mnis_mps_on_date()
mnis_opposition_posts()
mnis_other_parliaments()
mnis_parliamentary_posts()
mnis_parties()
mnis_preferred_names()
mnis_staff()
mnis_statuses()
mnis_peers_on_date()
The mnis_extra()
function acts as a wrapper to the additional information functions. By default it calls all functions, which is equivalent to mnis_full_biog()
.
There are seven fixed scope functions that return ready-made datasets. They are:
mnis_party_state()
mnis_constituency_results()
mnis_department()
mnis_general_election_results()
mnis_lords_type()
mnis_member_date()
mnis_party_state()
Fixed scope example, returning the state of all parties in the House of Commons, as reported on 2017-04-04.
library(mnis) x <- mnis_party_state("2017-04-04") x
The same fixed scope function, returning the state of all parties in the House of Lords, as reported on 2017-04-04.
y <- mnis_party_state("Lords", "2017-04-04") y
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.