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:

  • 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.

Installing mnis

From CRAN

install.packages("mnis")

Load mnis

library(mnis)

Using 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.

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

## # 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

## # 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

The following functions are part of the mnis_additional family. The mnis_full_biog() function returns all available information for a given MP, mnis_extra() returns data from some or all of the mnis_additional functions, based on the parameters it receives.

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_additional examples

## # A tibble: 1 x 379
##   member_id dods_id pims_id clerks_id display_as list_as full_title
## * <fct>     <fct>   <fct>   <fct>     <fct>      <fct>   <fct>     
## 1 172       25790   3572    1         Ms Diane … Abbott… Rt Hon Di…
## # ... with 372 more variables: date_of_birth <dttm>,
## #   date_of_death_nil <dttm>, date_of_death_label <dttm>, gender <fct>,
## #   party_id <fct>, party_text <fct>, house <fct>, member_from <fct>,
## #   house_start_date <dttm>, house_end_date_nil <dttm>,
## #   house_end_date_label <dttm>, current_status_id <fct>,
## #   current_status_is_active <fct>, current_status_name <fct>,
## #   current_status_start_date <dttm>, given_surname <fct>,
## #   given_middle_names <fct>, given_forename <fct>, town_of_birth <fct>,
## #   country_of_birth <fct>, gender <fct>, date_of_birth_nil <dttm>,
## #   date_of_birth_label <dttm>, date_of_retirement_nil <dttm>,
## #   date_of_retirement_label <dttm>, date_of_death_nil <dttm>,
## #   date_of_death_label <dttm>, preferred_name_title1 <fct>,
## #   preferred_name_title2 <fct>, preferred_name_surname1 <fct>,
## #   preferred_name_surname2 <fct>, preferred_name_middle_names1 <fct>,
## #   preferred_name_middle_names2 <fct>, preferred_name_forename1 <fct>,
## #   preferred_name_forename2 <fct>, preferred_name_suffix1 <fct>,
## #   preferred_name_suffix2 <fct>, preferred_name_address_as1 <fct>,
## #   preferred_name_address_as2 <fct>, preferred_name_note1 <fct>,
## #   preferred_name_note2 <fct>, preferred_name_start_date1 <dttm>,
## #   preferred_name_start_date2 <dttm>, preferred_name_end_date_nil <dttm>,
## #   preferred_name_end_date_label <dttm>, preferred_name_end_date <dttm>,
## #   preferred_name_list_as1 <fct>, preferred_name_list_as2 <fct>,
## #   preferred_name_display_as1 <fct>, preferred_name_display_as2 <fct>,
## #   preferred_name_full_title1 <fct>, preferred_name_full_title2 <fct>,
## #   preferred_name_honourary_prefixes_honourary_prefix_name1 <fct>,
## #   preferred_name_honourary_prefixes_honourary_prefix_name2 <fct>,
## #   house_membership_house <fct>, house_membership_start_date <dttm>,
## #   house_membership_end_date_nil <dttm>,
## #   house_membership_end_date_label <dttm>, constituency_id1 <fct>,
## #   constituency_id2 <fct>, constituency_id3 <fct>,
## #   constituency_id4 <fct>, constituency_id5 <fct>,
## #   constituency_id6 <fct>, constituency_id7 <fct>,
## #   constituency_id8 <fct>, constituency_name1 <fct>,
## #   constituency_name2 <fct>, constituency_name3 <fct>,
## #   constituency_name4 <fct>, constituency_name5 <fct>,
## #   constituency_name6 <fct>, constituency_name7 <fct>,
## #   constituency_name8 <fct>, constituency_start_date1 <dttm>,
## #   constituency_start_date2 <dttm>, constituency_start_date3 <dttm>,
## #   constituency_start_date4 <dttm>, constituency_start_date5 <dttm>,
## #   constituency_start_date6 <dttm>, constituency_start_date7 <dttm>,
## #   constituency_start_date8 <dttm>, constituency_end_date_nil <dttm>,
## #   constituency_end_date_label <dttm>, constituency_end_date3 <dttm>,
## #   constituency_end_date4 <dttm>, constituency_end_date5 <dttm>,
## #   constituency_end_date6 <dttm>, constituency_end_date7 <dttm>,
## #   constituency_end_date8 <dttm>, constituency_end_date9 <dttm>,
## #   constituency_end_reason1 <fct>, constituency_end_reason2 <fct>,
## #   constituency_end_reason3 <fct>, constituency_end_reason4 <fct>,
## #   constituency_end_reason5 <fct>, constituency_end_reason6 <fct>,
## #   constituency_end_reason7 <fct>, constituency_end_reason8 <fct>,
## #   constituency_entry_type1 <fct>, …

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.

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