Hansard Example

Evan Odell

2016-11-12

hansard is an R package to pull data from the UK parliament through the http://www.data.parliament.uk/ API. It emphasises simplicity and ease of use, so that users unfamiliar with APIs can easily retrieve large volumes of high quality data. Each function accepts a single argument at a time, and functions that require additional information to retrieve the data you requested will ask for it after you execute the function.

Installing hansard

From CRAN

install.packages(“hansard”)

From GitHub (Development Version)

install.packages(“devtools”) devtools::install_github(“EvanOdell/hansard”)

Load hansard

library(“hansard”)

Using hansard

There are 24 functions that currently work with the Parliamentary API:

all_answered_questions

bills

commons_answered_questions

commons_divisions

commons_oral_question_times

commons_oral_questions

commons_terms

commons_written_questions

constituencies

early_day_motions

election_results

elections

epetition

lords_ammendments

lords_attendance

lords_divisions

lords_written_questions

members

members_search

papers_laid

publication_logs

research_briefings

sessions_info

tv_programmes

Using commons_divisions

The commons_divisions function returns divisions in the House of Commons and the divisions that a member votes no or aye in. The example below returns all Commons Divisions where Diane Abbott voted aye.

x <- commons_divisions("aye")
#> Enter Member ID: 172
#> Retrieving page 1 of 4
#> Retrieving page 2 of 4
#> Retrieving page 3 of 4
#> Retrieving page 4 of 4
#> head(x)
#>  _about                                                              title
#> 1 http://data.parliament.uk/resources/626911                            Opposition Motion: Community Pharmacies
#> 2 http://data.parliament.uk/resources/626953                           Opposition Motion: Police Officer Safety
#> 3 http://data.parliament.uk/resources/621252                                           Opposition Motion: Yemen
#> 4 http://data.parliament.uk/resources/607490 Closure Motion: Sexual Offences (Pardons Etc.) Bill second reading
#> 5 http://data.parliament.uk/resources/582798      Opposition Motion: NHS sustainabiliy and transformation plans
#> 6 http://data.parliament.uk/resources/576587                                Finance Bill: Report Stage Amdt 174
#>                 uin date._value date._datatype
#> 1 CD:2016-11-02:142  2016-11-02       dateTime
#> 2 CD:2016-11-02:143  2016-11-02       dateTime
#> 3 CD:2016-10-26:139  2016-10-26       dateTime
#> 4 CD:2016-10-21:138  2016-10-21       dateTime
#> 5 CD:2016-09-14:134  2016-09-14       dateTime
#> 6 CD:2016-09-06:125  2016-09-06       dateTime

Using research_briefings

The function research_briefings is unusual in that it requests names instead of codes.

#> x <- research_briefings('topicSubTopic')
#> Sub-topics are case sensititve. To return list of sub-topics, enter yes.
#> Enter sub-topic: yes
#
#> [1] 'Agriculture, animals, food and rural affairs' 'Asylum, immigration and nationality'
#> [3] 'Business, industry and consumers'             'Communities and families'
#> [5] 'Crime, civil law, justice and rights'         'Culture, media and sport'
#> [7] 'Defence'                                      'Economy and finance'
#> [9] 'Education'                                    'Employment and training'
#> [11] 'Energy and environment'                       'European Union'
#> [13] 'Health services and medicine'                 'Housing and planning'
#> [15] 'International affairs'                        'Parliament, government and politics'
#> [17] 'Science and technology'                       'Social Security and pensions'
#> [19] 'Social services'                              'Transport'
#> Enter Topic. For ease of use, copy and paste the topic: Education
#> Sub-topics are case sensititve. To return list of sub-topics, enter yes.
#> Enter sub-topic: yes

#> [1] "Adult education"              "Further education"           
#> [3] "Higher education"             "Local authorities: education"
#> [5] "Ofsted"                       "Pre-school education"        
#> [7] "Schools"                      "Special educational needs"   
#> [9] "Students"                     "Teachers"   
#> Enter sub-topic. For ease of use, copy and paste the sub-topic: Teachers