The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

Introduction to mnis

Evan Odell

2021-04-03

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:

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

All mnis functions contain two parameters, tidy and tidy_style:

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
## # A tibble: 22 x 2
##    Title.Title_Id Title.Name
##    <chr>          <chr>     
##  1 22             Canon     
##  2 1              Dame      
##  3 2              Dr        
##  4 3              Hon       
##  5 4              Lady      
##  6 5              Lord      
##  7 6              Lt Col    
##  8 21             Lt Gen    
##  9 7              Miss      
## 10 8              Mr        
## # … with 12 more rows

With the tidy parameter

library(mnis)
x <- ref_titles(tidy = TRUE)
x
## # A tibble: 22 x 2
##    title_id name  
##    <chr>    <chr> 
##  1 22       Canon 
##  2 1        Dame  
##  3 2        Dr    
##  4 3        Hon   
##  5 4        Lady  
##  6 5        Lord  
##  7 6        Lt Col
##  8 21       Lt Gen
##  9 7        Miss  
## 10 8        Mr    
## # … with 12 more rows

###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_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()

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("2017-04-04")
x
## # A tibble: 14 x 6
##    id    name               male_count female_count non_binary_count total_count
##    <chr> <chr>              <chr>      <chr>        <chr>            <chr>      
##  1 4     Conservative       195        68           0                263        
##  2 6     Crossbench         136        46           0                182        
##  3 15    Labour             116        62           0                178        
##  4 17    Liberal Democrat   54         32           0                86         
##  5 49    Non-affiliated     39         8            0                47         
##  6 3     Bishops            21         5            0                26         
##  7 7     Democratic Unioni… 5          0            0                5          
##  8 44    Green Party        0          2            0                2          
##  9 38    Ulster Unionist P… 2          0            0                2          
## 10 5     Conservative Inde… 1          0            0                1          
## 11 53    Independent Socia… 1          0            0                1          
## 12 43    Labour Independent 0          1            0                1          
## 13 283   Lord Speaker       1          0            0                1          
## 14 22    Plaid Cymru        1          0            0                1

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
## # A tibble: 15 x 6
##    id    name               male_count female_count non_binary_count total_count
##    <chr> <chr>              <chr>      <chr>        <chr>            <chr>      
##  1 4     Conservative       192        62           0                254        
##  2 15    Labour             137        65           0                202        
##  3 6     Crossbench         138        40           0                178        
##  4 17    Liberal Democrat   68         34           0                102        
##  5 49    Non-affiliated     26         3            0                29         
##  6 3     Bishops            23         2            0                25         
##  7 7     Democratic Unioni… 3          0            0                3          
##  8 35    UK Independence P… 3          0            0                3          
##  9 10    Independent Labour 2          0            0                2          
## 10 38    Ulster Unionist P… 2          0            0                2          
## 11 44    Green Party        0          1            0                1          
## 12 53    Independent Socia… 1          0            0                1          
## 13 52    Independent Ulste… 1          0            0                1          
## 14 283   Lord Speaker       1          0            0                1          
## 15 22    Plaid Cymru        1          0            0                1

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.