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 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:
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 functions contain two parameters,
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
The naming convention for variables used if
tidy==TRUE is indicated by
tidy_style accepts one of
"period.case", defaulting to
"snake_case". All variable names will be converted to match the given naming convention.
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.
library(mnis) x <- ref_titles(tidy = FALSE) x
library(mnis) x <- ref_titles(tidy = TRUE) x
mnis_extra() function acts as a wrapper to the additional information functions. By default it calls all functions, which is equivalent to
There are seven fixed scope functions that return ready-made datasets. They are:
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.