Introduction to mnis

Evan Odell

2017-04-15

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 three main types:

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.

Installing mnis

From CRAN

install.packages("mnis")

From GitHub (Development Version)

install.packages("devtools")
devtools::install_github("EvanOdell/mnis")

Load mnis

library(mnis)

Using mnis

mnis_base function

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

Reference Functions

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

#   Title_Id         Name
#1        22        Canon
#2         1         Dame
#4         3          Hon
#3         2           Dr
#6         5         Lord
#5         4         Lady
#7         6       Lt Col
#8        21       Lt Gen
#9         7         Miss
#10        8           Mr
#11        9          Mrs
#12       10           Ms
#13       11         Prof
#14       19    Professor
#15       12          Rev
#16       13       Rev Dr
#17       18         Revd
#18       20      Revd Dr
#20       15          Sir
#19       14     Reverend
#21       16      The Rev
#22       17 The Reverend

With the tidy parameter

library(mnis)
x <- ref_titles(tidy = TRUE)
x

#   title_id         name
#1        22        Canon
#2         1         Dame
#4         3          Hon
#3         2           Dr
#6         5         Lord
#5         4         Lady
#7         6       Lt Col
#8        21       Lt Gen
#9         7         Miss
#10        8           Mr
#11        9          Mrs
#12       10           Ms
#13       11         Prof
#14       19    Professor
#15       12          Rev
#16       13       Rev Dr
#17       18         Revd
#18       20      Revd Dr
#20       15          Sir
#19       14     Reverend
#21       16      The Rev
#22       17 The Reverend

Additional Information Functions

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_opposition_posts()

mnis_other_parliaments()

mnis_parliamentary_posts()

mnis_parties()

mnis_preferred_names()

mnis_staff()

mnis_statuses()

mnis_extra()

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().

Fixed Scope Functions

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

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()
x

#         house party_id                       party_name party_male_count party_female_count party_total_count
# 1  Commons        4                     Conservative              260                 70               330
# 2  Commons       15                           Labour              128                101               229
# 3  Commons       29          Scottish National Party               36                 18                54
# 4  Commons       17                 Liberal Democrat                8                  1                 9
# 5  Commons        7        Democratic Unionist Party                8                  0                 8
# 6  Commons        8                      Independent                1                  3                 4
# 7  Commons       30                        Sinn Fein                4                  0                 4
# 8  Commons       22                      Plaid Cymru                2                  1                 3
# 9  Commons       31 Social Democratic & Labour Party                2                  1                 3
# 10 Commons       38            Ulster Unionist Party                2                  0                 2
# 11 Commons       44                      Green Party                0                  1                 1
# 12 Commons       47                          Speaker                1                  0                 1
# 13 Commons       35            UK Independence Party                1                  0                 1
# 14 Commons        0                           Vacant                0                  0                 1

Data tidying

mnis contains a parameter option called tidy with all functions except for mnis_base. The default variable names are unnecessarily lengthy, repeat the same piece of information several times in a row and contain non-alphanumeric characters. They also use a mixture of camelCase, .s, @s and #s to seperate words in multi-word variable names. 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.

There is also an internal function to remove byte-order marks from the API response.