introduction.Rmd
legcoplus
is an R package to reorganise and present data from the Hong Kong Legislative Council (LegCo) APIs in a more useable manner. It provides functions that restructure data from multiple API requests to enhance the efficiency of the use of LegCo’s APIs.
This package requires the package legco
to fetch LegCo’s open data. To install legco
:
install.packages("devtools")
devtools::install_github("elgarteo/legco")
install.packages("devtools")
devtools::install_github("elgarteo/legcoplus")
And to load it before every use:
library(legcoplus)
The package contains the following functions:
answered_questions()
fetches more detailed information and the full text of questions put on the government by any given LegCo member.legco_member_affiliation
contains the declared political affiliation and constituency of every member in each term.member_voting_record()
returns the voting record in Council and committee meetings.search_committee()
searches committee by full or partial name of committee.search_division()
searches all division(s) (or votes) held in Council, House Committee, Finance Committe and its subcommittees meetings on any given date, by any given committee/subcommittee or during any given meeting slot.search_member()
searches everyone who speaks in LegCo with unique identifiers from different LegCo APIs’ databases or full or partial name.All functions can also be accessed with the prefix legco_
, e.g. legco_answered_questions()
and answered_questions()
return the same result.
LegCo APIs have an access limit of appraximately 1000 requests per hour per IP. As some of the functions in this package (such as answered_questions()
) make multiple requests at a time, the limit can be reached very easily. It is therefore advised to retrieve the data in smaller packets.
The function legco::questions()
returns only the subject of the question put on the government but not the full text and the answering body:
legco::questions(rundown_id = 294209)
## MeetingDate QuestionType
## 1 2013-01-23T00:00:00 Oral
## Subject Speaker SpeakerID
## 1 Policy on Public Access to Government Information KENNETH CHAN 106
## RundownID
## 1 294209
## HansardFileURL
## 1 https://www.legco.gov.hk/yr12-13/english/counmtg/hansard/cm0123-translate-e.pdf#nameddest=orq01
While the function answered_questions()
fetches the question text and other detailed information as well:
w <- answered_questions(rundown_id = 294209)
Note that if verbose
is enabled (which is by default), multiple messages will be shown. They are created when the function is making multiple requests to the APIs. The actual number of records in the final output data frame is displayed in the last message. For instance, it is 1 in the example above.
answered_questions()
returns the asking members of the main question and the supplementary questions (if any):
# All asking members (including supplementary questions)
legco::speakers(w$AskingSpeakerID)
## SpeakerID NameChi NameEng Type Initial FirstName LastName
## 1 109 梁繼昌 KENNETH LEUNG MB KL Kai-cheong LEUNG
## 2 106 陳家洛 KENNETH CHAN MB KC Ka-lok CHAN
## 3 66 湯家驊 RONNY TONG MB TKW Ka-wah TONG
## 4 95 田北俊 JAMES TIEN MB TPC Pei-chun TIEN
## 5 91 黃毓民 WONG YUK-MAN MB WYM Yuk-man WONG
# The answering official of the question
legco::speakers(w$AnsweringSpeakerID)
## SpeakerID NameChi
## 1 15 政制及內地事務局局長
## 2 13 財經事務及庫務局局長
## NameEng Type Initial FirstName
## 1 SECRETARY FOR CONSTITUTIONAL AND MAINLAND AFFAIRS PO SCMA
## 2 SECRETARY FOR FINANCIAL SERVICES AND THE TREASURY PO SFST
## LastName
## 1
## 2
The full text of the main question, supplementary questions (if any), answers and miscellaneous conversations (e.g. some member rising to a point of order) are contained in lists:
## [1] "MR KENNETH LEUNG (in Cantonese): My supplementary question is: Throughout the years, how many complaints about privacy have been lodged by directors in relation to the arrangement concerning the inspection of the Companies Register? "
## [1] "SECRETARY FOR FINANCIAL SERVICES AND THE TREASURY (in Cantonese): In dealing with the Companies Ordinance, the target of consultation is the public, and we had widely promoted the relevant contents. I think we had already extensively consulted the public. "
## [1] "PRESIDENT (in Cantonese): Which Secretary will reply? Secretary for Financial Services and the Treasury, please reply. "
It is also possible to fetch all questions raised by any given member and filter by parameters that are supported by legco::questions()
.
# Search all written questions asked by SpeakerID 61 and MemberID 209
# from January to April 2019 in Chinese
w <- answered_questions(speaker_id = 61, member_id = 209,
from = "2019-01-01", to ="2019-04-30",
type = "written", lang = "zh")
w[, 1:5]
## MeetingDate QuestionType Subject
## 1 2019-01-16T00:00:00 Written 有關南丫島附近撞船事故的跟進行動
## 2 2019-01-16T00:00:00 Written 延長產假措施對人手的影響
## 3 2019-01-30T00:00:00 Written 打擊引致擠塞的交通罪行
## 4 2019-02-27T00:00:00 Written 推廣智力運動
## 5 2019-03-27T00:00:00 Written 領展房地產投資信託基金擁有或售出的停車場
## 6 2019-04-03T00:00:00 Written 為永久造口病人提供財政資助
## Speaker SpeakerID
## 1 涂謹申 39
## 2 李國麟 61
## 3 涂謹申 39
## 4 涂謹申 39
## 5 涂謹申 39
## 6 李國麟 61
legco_member_affiliation
is a list containing data frames of the political affiliation and constituency of every member in each LegCo term. The dataframes are named by the respective TermID
they represent. For example, to fetch the data of the fifth term of LegCo:
# Political affiliation of the sixth term of LegCo
w <- legco_member_affiliation[["5"]]
head(w)
## SpeakerID MemberID NameEng NameChi TypeEng TypeChi
## 1 63 260 Andrew LEUNG Kwan-yuen 梁君彥 Functional 功能界別
## 2 39 209 James TO Kun-sun 涂謹申 Functional 功能界別
## 3 43 134 LEUNG Yiu-chung 梁耀忠 Functional 功能界別
## 4 53 187 Abraham SHEK Lai-him 石禮謙 Functional 功能界別
## 5 55 55 Tommy CHEUNG Yu-yan 張宇人 Functional 功能界別
## 6 61 258 Joseph LEE Kok-long 李國麟 Functional 功能界別
## ConstituencyEng ConstituencyChi
## 1 Industrial (First) 工業界(第一)
## 2 District Council (Second) 區議會(第二)
## 3 District Council (Second) 區議會(第二)
## 4 Real Estate and Construction 地產及建造界
## 5 Catering 飲食界
## 6 Health Services 衞生服務界
## AffiliationEng AffiliationChi
## 1 Business and Professionals Alliance for Hong Kong 香港經濟民生聯盟
## 2 Democratic Party 民主黨
## 3 Neighbourhood and Worker’s Service Centre 街坊工友服務處
## 4 Business and Professionals Alliance for Hong Kong 香港經濟民生聯盟
## 5 Liberal Party 自由黨
## 6
The function legco::voting_record()
of the Voting Results Database does not accept filtering parameters of any unique identifier from other databases such as SpeakerID
, MemberID
, CommitteeID
and SlotID
. Instead, it only takes the full Chinese names of LegCo members and full English name of the committee. With the function member_voting_record()
, it is possible to apply these idenitifers to search the voting results.
# Search the voting records of SpeakerID 102 and MemberID 910
# in CommitteeID 2567 since June 15, 2019.
w <- member_voting_record(speaker_id = 102, member_id = 910,
committee_id = 2567, from = "2019-06-15")
head(w)
## VoteTime Committee TermID
## 1 2019-06-28T15:57:41 Finance Committee 5
## 2 2019-06-28T15:57:41 Finance Committee 5
## 3 2019-06-28T16:45:28 Finance Committee 5
## 4 2019-06-28T16:45:28 Finance Committee 5
## 5 2019-06-28T18:45:03 Finance Committee 5
## 6 2019-06-28T18:45:03 Finance Committee 5
## MotionEn
## 1 Motion that discussion on FCR(2019-20)4 – PWSC(2018-19)32 be now adjourned
## 2 Motion that discussion on FCR(2019-20)4 – PWSC(2018-19)32 be now adjourned
## 3 FCR(2019-20)4 – PWSC(2018-19)32 RECOMMENDATION OF THE PUBLIC WORKS SUBCOMMITTEE MADE ON 20 MARCH 2019 – Organic Resources Recovery Centre Phase 2
## 4 FCR(2019-20)4 – PWSC(2018-19)32 RECOMMENDATION OF THE PUBLIC WORKS SUBCOMMITTEE MADE ON 20 MARCH 2019 – Organic Resources Recovery Centre Phase 2
## 5 FCR(2019-20)11 (a) Injection of $20 billion into the Research Endowment Fund, (b) rationalising the use of investment income of different pots of endowment of the Research Endowment Fund and (c) a new commitment of $3 billion for launching the Research Matching Grant Scheme for three years
## 6 FCR(2019-20)11 (a) Injection of $20 billion into the Research Endowment Fund, (b) rationalising the use of investment income of different pots of endowment of the Research Endowment Fund and (c) a new commitment of $3 billion for launching the Research Matching Grant Scheme for three years
## MotionCh
## 1 動議中止議程文件FCR(2019-20)4 – PWSC(2018-19)32的討論
## 2 動議中止議程文件FCR(2019-20)4 – PWSC(2018-19)32的討論
## 3 FCR(2019-20)4 – PWSC(2018-19)32 工務小組委員會在2019年3月20日所提出的建議 – 有機資源回收中心第二期
## 4 FCR(2019-20)4 – PWSC(2018-19)32 工務小組委員會在2019年3月20日所提出的建議 – 有機資源回收中心第二期
## 5 FCR(2019-20)11 (a)向研究基金注資200億元;(b) 理順研究基金內不同款項所賺取投資收入的運用,以及(c)開立新承擔額30億元,設立研究配對補助金計劃,為期3年
## 6 FCR(2019-20)11 (a)向研究基金注資200億元;(b) 理順研究基金內不同款項所賺取投資收入的運用,以及(c)開立新承擔額30億元,設立研究配對補助金計劃,為期3年
## OverallResult NameCh NameEn Vote
## 1 Negatived 馬逢國 MA Fung-kwok No
## 2 Negatived 朱凱廸 CHU Hoi-dick Yes
## 3 Passed 馬逢國 MA Fung-kwok Yes
## 4 Passed 朱凱廸 CHU Hoi-dick Yes
## 5 Passed 馬逢國 MA Fung-kwok Yes
## 6 Passed 朱凱廸 CHU Hoi-dick Yes
# Search the voting records of meeting with SlotID
w <- member_voting_record(slot_id = 177529)
head(w)
## VoteTime Committee TermID
## 1 2019-06-19T09:31:49 Public Works Subcommittee 5
## 2 2019-06-19T09:31:49 Public Works Subcommittee 5
## 3 2019-06-19T09:31:49 Public Works Subcommittee 5
## 4 2019-06-19T09:31:49 Public Works Subcommittee 5
## 5 2019-06-19T09:31:49 Public Works Subcommittee 5
## 6 2019-06-19T09:31:49 Public Works Subcommittee 5
## MotionEn
## 1 PWSC(2019-20)17 Campus Expansion at Ho Man Tin Slope
## 2 PWSC(2019-20)17 Campus Expansion at Ho Man Tin Slope
## 3 PWSC(2019-20)17 Campus Expansion at Ho Man Tin Slope
## 4 PWSC(2019-20)17 Campus Expansion at Ho Man Tin Slope
## 5 PWSC(2019-20)17 Campus Expansion at Ho Man Tin Slope
## 6 PWSC(2019-20)17 Campus Expansion at Ho Man Tin Slope
## MotionCh OverallResult NameCh
## 1 PWSC(2019-20)17 何文田斜坡校園擴建工程 Passed 盧偉國
## 2 PWSC(2019-20)17 何文田斜坡校園擴建工程 Passed 石禮謙
## 3 PWSC(2019-20)17 何文田斜坡校園擴建工程 Passed 張宇人
## 4 PWSC(2019-20)17 何文田斜坡校園擴建工程 Passed 李慧琼
## 5 PWSC(2019-20)17 何文田斜坡校園擴建工程 Passed 陳克勤
## 6 PWSC(2019-20)17 何文田斜坡校園擴建工程 Passed 梁美芬
## NameEn Vote
## 1 Ir Dr LO Wai-kwok Present
## 2 Abraham SHEK Absent
## 3 Tommy CHEUNG Yes
## 4 Starry LEE Yes
## 5 CHAN Hak-kan Yes
## 6 Dr Priscilla LEUNG Yes
The function search_committee()
allows searching committee with full or partial name of the committee:
# Search all Bills Committees established in the sixth term of LegCo
w <- search_committee(search_term = "bills committee", term_id = 5)
head(w[, 1:4])
## CommitteeID CommitteeCode
## 1 2724 BC/1/16
## 2 2834 BC/1/17
## 3 2960 BC/1/18
## 4 3011 BC/10/18
## 5 2712 BC/101/16
## 6 2844 BC/101/17
## NameEng
## 1 Bills Committee on Stamp Duty (Amendment) Bill 2017 and Stamp Duty (Amendment) (No. 2) Bill 2017
## 2 Bills Committee on Inland Revenue (Amendment) (No. 5) Bill 2017
## 3 Bills Committee on Inland Revenue (Amendment) (No. 6) Bill 2018
## 4 Bills Committee on Occupational Retirement Schemes (Amendment) Bill 2019
## 5 Bills Committee on Arbitration (Amendment) Bill 2016
## 6 Bills Committee on Banking (Amendment) Bill 2017
## NameChi
## 1 《2017年印花稅(修訂)條例草案》及《2017年印花稅(修訂)(第2號)條例草案》委員會
## 2 《2017年稅務(修訂)(第5號)條例草案》委員會
## 3 《2018年稅務(修訂)(第6號)條例草案》委員會
## 4 《2019年職業退休計劃(修訂)條例草案》委員會
## 5 《2016年仲裁(修訂)條例草案》委員會
## 6 《2017年銀行業(修訂)條例草案》委員會
By default, search_committee()
returns results with the exact match of the search term. It is possible to disable exact matching so that the function returns results containing any of the English words/Chinese characters in the search term:
# Search all committees with either "taxi" or "ferry" in the name
w <- search_committee(search_term = "taxi ferry", exact = FALSE)
w[, 1:4]
## CommitteeID CommitteeCode
## 1 3016 BC/102/18
## 2 2905 BC/104/17
## NameEng
## 1 Bills Committee on Franchised Taxi Services Bill
## 2 Bills Committee on Ferry Services (Amendment) Bill 2018
## NameChi
## 1 《專營的士服務條例草案》委員會
## 2 《2018年渡輪服務(修訂)條例草案》委員會
# Search all committees with either "動" or "植" in the name
w <- search_committee(search_term = "動植", exact = FALSE)
head(w[, 1:4])
## CommitteeID CommitteeCode
## 1 2737 BC/53/16
## 2 2768 BC/6/16
## 3 2492 PL/FE/S3
## 4 2703 PL/FE/S4
## 5 2992 PL/TP/S2
## 6 2318 SC/10/13
## NameEng
## 1 Bills Committee on Cross-boundary Movement of Physical Currency and Bearer Negotiable Instruments Bill
## 2 Bills Committee on Protection of Endangered Species of Animals and Plants (Amendment) Bill 2017
## 3 Subcommittee on Issues Relating to Animal Welfare and Cruelty to Animals
## 4 Subcommittee to Study Issues Relating to Animal Rights
## 5 Subcommittee on Hillside Escalator Links and Elevator Systems
## 6 Subcommittee on Proposed Resolution under Section 5(4) of the Motor Vehicles (First Registration Tax) Ordinance
## NameChi
## 1 《實體貨幣及不記名可轉讓票據跨境流動條例草案》委員會
## 2 《2017年保護瀕危動植物物種(修訂)條例草案》委員會
## 3 有關動物福利及殘酷對待動物事宜小組委員會
## 4 研究動物權益相關事宜小組委員會
## 5 上坡地區自動扶梯連接系統和升降機系統小組委員會
## 6 根據《汽車(首次登記稅)條例》第5(4)條動議的擬議決議案小組委員會
search_committee()
returns results containing the search term, including non-exact words. For instance, records containing the term "taxi"
are included in the search result of the search term "tax"
:
# Search result of "tax"
w <- search_committee(search_term = "tax")
w$NameEng
## [1] "Bills Committee on Franchised Taxi Services Bill"
## [2] "Bills Committee on Inland Revenue and MPF Schemes Legislation (Tax Deductions for Annuity Premiums and MPF Voluntary Contributions) (Amendment) Bill 2018"
## [3] "Bills Committee on Inland Revenue (Profits Tax Exemption for Funds) (Amendment) Bill 2018"
## [4] "Bills Committee on Inland Revenue (Amendment) (Tax Concessions) Bill 2019"
## [5] "Subcommittee on Tax Reserve Certificates (Rate of Interest) (Consolidation) (Amendment) Notice 2018"
## [6] "Subcommittee on Proposed Resolution under Section 5(4) of the Motor Vehicles (First Registration Tax) Ordinance"
## [7] "Subcommittee on Inland Revenue (Exchange of Information relating to Taxes) (United States of America) Order"
## [8] "Subcommittee on Specification of Arrangements (The Mainland of China) (Avoidance of Double Taxation and the Prevention of Fiscal Evasion with respect to Taxes on Income) (Fourth Protocol) Order"
## [9] "Subcommittee on Exemption from Profits Tax (People's Bank of China Debt Instrument) Order"
To have only exact words in the result, insert a space before and/or after the word, e.g. " tax "
:
# Search result of " tax "
w <- search_committee(search_term = " tax ")
w$NameEng
## [1] "Bills Committee on Inland Revenue (Profits Tax Exemption for Funds) (Amendment) Bill 2018"
## [2] "Subcommittee on Tax Reserve Certificates (Rate of Interest) (Consolidation) (Amendment) Notice 2018"
## [3] "Subcommittee on Exemption from Profits Tax (People's Bank of China Debt Instrument) Order"
legco::voting_record()
of the LegCo Voting Result Database does not support the use of individual identifiers in search and the presentation of an index of votes. With the function search_division()
, it is possible to search division(s) with CommitteeID, and SlotID:
# Search votes conducted on April 3, 2019 by the Establishment Subcommittee
w <- search_division(search_date = "2019-04-03", committee_id = 2943)
w[, c(1:4, 24)]
## VoteTime Committee TermID
## 1 2019-04-03T09:46:15 Establishment Subcommittee 5
## 33 2019-04-03T09:48:17 Establishment Subcommittee 5
## 65 2019-04-03T09:50:03 Establishment Subcommittee 5
## MotionCh
## 1 EC(2018-19)30建議將3個編外職位轉為常額職位,即土木工程拓展署的3個總工程師職位,以推展政策措施,增加短、中及長期的土地供應
## 33 EC(2018-19)30 - 建議開設1個編外職位,即地政總署的1 個總產業測量師職位,以及將1個編外職位轉為常額職位,即規劃署的1個總城市規劃師,以推展政策措施,增加短、中及長期的土地供應
## 65 EC(2018-19)30 - 建議在政府產業署開設1個編外職位,即1 個首長級丙級政務官職位,以及開設1個常額職位,即1個總產業測量師/首席物業估價測量師常額職位,以推展政策措施,增加短、中及長期的土地供應
## OverallYesCount
## 1 17
## 33 21
## 65 18
# Search vote conducted during a specific meeting
w <- search_division(slot_id = 179602)
w[, c(1:4, 24)]
## VoteTime Committee TermID MotionCh OverallYesCount
## 1 2019-04-03T19:07:55 Council Meeting 5 「毋忘六四」議案 NA
By default, search_division()
returns an index list of votes only. To fetch the voting record of each member:
# Search voting record of each member conducted during a specific meeting
w <- search_division(slot_id = 179602, index = FALSE)
head(w[, c(1:5, 28:29, 31)])
## VoteTime Committee TermID MotionCh
## 1 2019-04-03T19:07:55 Council Meeting 5 「毋忘六四」議案
## 2 2019-04-03T19:07:55 Council Meeting 5 「毋忘六四」議案
## 3 2019-04-03T19:07:55 Council Meeting 5 「毋忘六四」議案
## 4 2019-04-03T19:07:55 Council Meeting 5 「毋忘六四」議案
## 5 2019-04-03T19:07:55 Council Meeting 5 「毋忘六四」議案
## 6 2019-04-03T19:07:55 Council Meeting 5 「毋忘六四」議案
## MotionEn NameCh NameEn Vote
## 1 MOTION ON “NOT FORGETTING THE 4 JUNE INCIDENT” 梁君彥 Andrew LEUNG Present
## 2 MOTION ON “NOT FORGETTING THE 4 JUNE INCIDENT” 涂謹申 James TO Yes
## 3 MOTION ON “NOT FORGETTING THE 4 JUNE INCIDENT” 梁耀忠 LEUNG Yiu-chung Yes
## 4 MOTION ON “NOT FORGETTING THE 4 JUNE INCIDENT” 石禮謙 Abraham SHEK No
## 5 MOTION ON “NOT FORGETTING THE 4 JUNE INCIDENT” 張宇人 Tommy CHEUNG Abstain
## 6 MOTION ON “NOT FORGETTING THE 4 JUNE INCIDENT” 李國麟 Prof Joseph LEE Yes
The unique identifiers of different LegCo databases are not interchangeable, for instance SpeakerID
used in the Hansard Database and MemberID
used in the Schedule Database. search_member()
provides an easy way to work with SpeakerID
and MemberID
interchangeably:
# A combined list of all members from legco::speakers() and legco::member()
w <- search_member()
w[63:64, ]
## SpeakerID MemberID Type NameChi NameEng TermID TitleEng SurnameEng
## 63 161 929 MB 陳凱欣 CHAN HOI-YAN 5 CHAN
## 64 144 912 MB 容海恩 YUNG HOI-YAN 5 YUNG
## FirstnameEng EnglishName HonourableEng SurnameChi FirstnameChi TitleChi
## 63 Hoi-yan 陳 凱欣 議員
## 64 Hoi-yan JP 容 海恩 議員
## HonourableChi
## 63
## 64 JP
# Lookup the MemberID of SpeakerID 63
w <- search_member(speaker_id = 63)
w$MemberID
## [1] 260
# Lookup the SpeakerID of MemberID 273
w <- search_member(member_id = 273)
w$SpeakerID
## [1] 75
search_member()
also allows searching by full or partial name in English or Chinese:
# Lookup members with "謙" in their names
search_member(search_term = "謙")
## SpeakerID MemberID Type NameChi NameEng TermID TitleEng SurnameEng
## 1 82 101 MB 葉國謙 IP KWOK-HIM 4 Hon IP
## 2 53 187 MB 石禮謙 ABRAHAM SHEK 4, 5 Hon SHEK
## FirstnameEng EnglishName HonourableEng SurnameChi FirstnameChi TitleChi
## 1 Kwok-him GBS, JP 葉 國謙 議員
## 2 Lai-him Abraham GBS, JP 石 禮謙 議員
## HonourableChi
## 1 GBS, JP
## 2 GBS, JP
# Lookup members with "ting" in their names
search_member(search_term = "ting")
## SpeakerID MemberID Type NameChi NameEng TermID TitleEng SurnameEng
## 1 138 911 MB 林卓廷 LAM CHEUK-TING 5 LAM
## 2 65 267 MB 黃定光 WONG TING-KWONG 4, 5 Hon WONG
## FirstnameEng EnglishName HonourableEng SurnameChi FirstnameChi TitleChi
## 1 Cheuk-ting 林 卓廷 議員
## 2 Ting-kwong GBS, JP 黃 定光 議員
## HonourableChi
## 1
## 2 GBS, JP
The searching parameter of search_member()
has the same options with that of search_committee()
such as the exact search option. Refer here for detailed examples on how to apply these options in your search.