├── .github
├── .gitignore
└── workflows
│ ├── test-coverage.yaml
│ └── pr-commands.yaml
├── LICENSE
├── data-raw
├── .gitignore
├── mace.png
├── mace2.png
├── hex-sticker.R
└── data-prep.R
├── .gitattributes
├── inst
├── figures
│ └── imgfile.png
└── CITATION
├── docs
├── reference
│ └── Rplot001.png
├── pkgdown.yml
├── articles
│ └── introduction_files
│ │ ├── anchor-sections-1.0
│ │ ├── anchor-sections.css
│ │ └── anchor-sections.js
│ │ ├── header-attrs-2.1
│ │ └── header-attrs.js
│ │ ├── header-attrs-2.5
│ │ └── header-attrs.js
│ │ └── header-attrs-2.7
│ │ └── header-attrs.js
├── docsearch.json
├── link.svg
├── bootstrap-toc.css
├── docsearch.js
├── jquery.sticky-kit.min.js
└── pkgdown.js
├── tests
├── testthat-b.R
├── testthat-ea.R
├── testthat-ep.R
├── testthat-mp.R
├── testthat-r.R
├── testthat-all1q.R
├── testthat-all2q.R
├── testthat-com.R
├── testthat-con.R
├── testthat-mem.R
├── testthat-lords1.R
├── testthat-lords2.R
├── testthat-misc1.R
├── testthat-misc2.R
├── testthat-elections.R
├── testthat-election_results.R
├── testthat-election_candidates.R
└── testthat
│ ├── test_constituencies.R
│ ├── test_election_candidates.R
│ ├── test_election_results.R
│ ├── test_misc2.R
│ ├── test_research_briefings.R
│ ├── test_early_day_motions.R
│ ├── test_epetition.R
│ ├── test_2all_answered_questions.R
│ ├── test_bills.R
│ ├── test_1all_answered_questions.R
│ ├── test_elections.R
│ ├── test_members.R
│ ├── test_mp_misc.R
│ ├── test_lords1.R
│ ├── test_misc1.R
│ └── test_lords2.R
├── data
└── bill_publication_types.rda
├── .gitignore
├── codecov.yml
├── R
├── utils-house.R
├── data.R
├── utils-zzzz.R
├── utils-publogs.R
├── utils-bills.R
├── utils-epetition.R
├── utils-constit.R
├── utils-sessions.R
├── utils-question-query.R
├── utils-edm-loop.R
├── utils-elections.R
├── utils-hansard-tidy.R
├── utils-research.R
├── bill_stage_types.R
├── commons_division_date.R
├── constituencies.R
├── utils-mp-questions.R
├── lords_interests.R
├── utils-tv.R
├── lords_sessions.R
├── hansard-package.R
├── lords_attendance_date.R
├── commons_terms.R
├── members_search.R
├── utils-loop.R
├── lords_amendments.R
├── research_briefings_lists.R
├── bills.R
├── sessions_info.R
├── lords_attendance_session.R
├── epetition.R
├── bill_publications.R
├── papers_laid.R
├── publication_logs.R
├── epetition_tibble.R
├── commons_oral_questions.R
├── election_candidates.R
├── commons_oral_question_times.R
└── commons_written_questions.R
├── .Rbuildignore
├── cran-comments.md
├── hansard.Rproj
├── _pkgdown.yml
├── man
├── bill_publication_types.Rd
├── edm_text.Rd
├── bill_stage_types.Rd
├── research_briefings_lists.Rd
├── commons_division_date.Rd
├── hansard.Rd
├── lords_interests.Rd
├── constituencies.Rd
├── commons_terms.Rd
├── lords_attendance_date.Rd
├── members_search.Rd
├── epetition.Rd
├── lords_sessions.Rd
├── election_candidates.Rd
├── commons_oral_question_times.Rd
├── lords_amendments.Rd
├── papers_laid.Rd
├── publication_logs.Rd
├── bills.Rd
├── sessions_info.Rd
├── lords_attendance_session.Rd
├── members.Rd
├── mp_vote_record.Rd
├── lords_divisions.Rd
├── research_briefings.Rd
├── bill_publications.Rd
├── lord_vote_record.Rd
├── epetition_tibble.Rd
├── mp_questions.Rd
├── commons_written_questions.Rd
├── commons_divisions.Rd
└── election_results.Rd
├── LICENSE.md
├── DESCRIPTION
├── appveyor.yml
├── CODE_OF_CONDUCT.md
├── README.md
└── NAMESPACE
/.github/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | YEAR: 2018
2 | COPYRIGHT HOLDER: Evan Odell
3 |
--------------------------------------------------------------------------------
/data-raw/.gitignore:
--------------------------------------------------------------------------------
1 | BF1_Ottoman_Flanged_Mace_Icon.png
2 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 | data/* binary
3 | src/* text=lf
4 | R/* text=lf
5 |
--------------------------------------------------------------------------------
/data-raw/mace.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanodell/hansard/HEAD/data-raw/mace.png
--------------------------------------------------------------------------------
/data-raw/mace2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanodell/hansard/HEAD/data-raw/mace2.png
--------------------------------------------------------------------------------
/inst/figures/imgfile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanodell/hansard/HEAD/inst/figures/imgfile.png
--------------------------------------------------------------------------------
/docs/reference/Rplot001.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanodell/hansard/HEAD/docs/reference/Rplot001.png
--------------------------------------------------------------------------------
/tests/testthat-b.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "b")
5 |
--------------------------------------------------------------------------------
/tests/testthat-ea.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "ea")
5 |
--------------------------------------------------------------------------------
/tests/testthat-ep.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "ep")
5 |
--------------------------------------------------------------------------------
/tests/testthat-mp.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "mp")
5 |
--------------------------------------------------------------------------------
/tests/testthat-r.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "r")
5 |
--------------------------------------------------------------------------------
/tests/testthat-all1q.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "1all")
5 |
--------------------------------------------------------------------------------
/tests/testthat-all2q.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "2all")
5 |
--------------------------------------------------------------------------------
/tests/testthat-com.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "com")
5 |
--------------------------------------------------------------------------------
/tests/testthat-con.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "con")
5 |
--------------------------------------------------------------------------------
/tests/testthat-mem.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "mem")
5 |
--------------------------------------------------------------------------------
/data/bill_publication_types.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/evanodell/hansard/HEAD/data/bill_publication_types.rda
--------------------------------------------------------------------------------
/tests/testthat-lords1.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "lords1")
5 |
--------------------------------------------------------------------------------
/tests/testthat-lords2.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "lords2")
5 |
--------------------------------------------------------------------------------
/tests/testthat-misc1.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "misc1")
5 |
--------------------------------------------------------------------------------
/tests/testthat-misc2.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "misc2")
5 |
--------------------------------------------------------------------------------
/tests/testthat-elections.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "elections")
5 |
--------------------------------------------------------------------------------
/tests/testthat-election_results.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "election_results")
5 |
--------------------------------------------------------------------------------
/tests/testthat-election_candidates.R:
--------------------------------------------------------------------------------
1 | library(testthat)
2 | library(hansard)
3 |
4 | test_check("hansard", filter = "election_candidates")
5 |
--------------------------------------------------------------------------------
/docs/pkgdown.yml:
--------------------------------------------------------------------------------
1 | pandoc: '2.13'
2 | pkgdown: 1.6.1
3 | pkgdown_sha: ~
4 | articles:
5 | introduction: introduction.html
6 | last_built: 2021-04-04T15:27Z
7 |
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 | .Ruserdata
5 | hansard.Rproj
6 | inst/doc
7 | data.kml
8 | .Rd2pdf41583
9 | README.html
10 | vignettes/introduction.R
11 | vignettes/introduction.html
12 |
--------------------------------------------------------------------------------
/data-raw/hex-sticker.R:
--------------------------------------------------------------------------------
1 | library(hexSticker)
2 | library(ggplot2)
3 |
4 | sticker("./data-raw/mace2.png",
5 | package = "hansard", p_size = 8, s_x = 1, s_y = .75,
6 | s_width = .6, h_fill = "#4A7729", h_color = "#971B2F",
7 | filename = "inst/figures/imgfile.png"
8 | )
9 |
--------------------------------------------------------------------------------
/docs/articles/introduction_files/anchor-sections-1.0/anchor-sections.css:
--------------------------------------------------------------------------------
1 | /* Styles for section anchors */
2 | a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;}
3 | a.anchor-section::before {content: '#';}
4 | .hasAnchor:hover a.anchor-section {visibility: visible;}
5 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | comment: false
2 |
3 | coverage:
4 | status:
5 | project:
6 | default:
7 | target: auto
8 | threshold: 1%
9 | informational: true
10 | patch:
11 | default:
12 | target: auto
13 | threshold: 1%
14 | informational: true
15 |
--------------------------------------------------------------------------------
/R/utils-house.R:
--------------------------------------------------------------------------------
1 |
2 | house_query_util <- function(house) {
3 | if (house == "commons") {
4 | house_query <- "&legislature.prefLabel=House%20of%20Commons"
5 | } else if (house == "lords") {
6 | house_query <- "&legislature.prefLabel=House%20of%20Lords"
7 | } else {
8 | house_query <- ""
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/R/data.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' A character vector of possible types of bill publications.
4 | #' For use with [bill_publications()]
5 | #'
6 | #' @seealso [bill_publications()]
7 | #' @seealso [bills()]
8 | #' @seealso [bill_stage_types()]
9 | #'
10 | #' @format A character vector containing 38 elements
11 | "bill_publication_types"
12 |
--------------------------------------------------------------------------------
/R/utils-zzzz.R:
--------------------------------------------------------------------------------
1 | ## Base URL for API calls
2 | url_util <- "https://lda.data.parliament.uk/"
3 |
4 | veb <- function(verbose) {
5 | if (verbose) {
6 | message("Connecting to API")
7 | }
8 | }
9 |
10 | jpage_func <- function(query) {
11 | x <- jsonlite::fromJSON(paste0(query, "&_pageSize=1"), flatten = TRUE)
12 |
13 | floor(x$result$totalResults / 100)
14 | }
15 |
--------------------------------------------------------------------------------
/R/utils-publogs.R:
--------------------------------------------------------------------------------
1 |
2 | # publication logs tidying ------------------------------------------------
3 |
4 | pub_tidy <- function(df, tidy_style) {
5 | if (nrow(df) > 0) {
6 | df$publicationDate._value <- as.POSIXct(df$publicationDate._value)
7 |
8 | df$publicationDate._datatype <- "POSIXct"
9 | }
10 |
11 | df <- hansard_tidy(df, tidy_style)
12 |
13 | df
14 | }
15 |
--------------------------------------------------------------------------------
/inst/CITATION:
--------------------------------------------------------------------------------
1 | note <- sprintf("R package version %s", meta$Version)
2 |
3 | bibentry(bibtype = "Manual",
4 | title = "{hansard}: Provides Easy Downloading Capabilities for the UK Parliament API",
5 | author = c(person("Evan", "Odell")),
6 | year = 2017,
7 | note = note,
8 | doi = "10.5281/zenodo.591264",
9 | url = "https://cran.r-project.org/package=hansard")
10 |
--------------------------------------------------------------------------------
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^CRAN-RELEASE$
2 | ^.*\.Rproj$
3 | ^\.Rproj\.user$
4 | ^cran-comments\.md$
5 | ^.*\.RData$
6 | ^.*\.Rhistory$
7 | ^\.travis\.yml$
8 | ^README\.Rmd$
9 | ^README-.*\.png$
10 | ^data-raw$
11 | ^codecov\.yml$
12 | ^docs$
13 | ^mp_edms_cleanbit\.txt$
14 | ^_pkgdown\.yml$
15 | ^README\.html$
16 | ^appveyor\.yml$
17 | ^testing\.R$
18 | ^code for wrappers$
19 | ^LICENSE\.md$
20 | ^CODE_OF_CONDUCT\.md$
21 | ^\.github$
22 |
--------------------------------------------------------------------------------
/R/utils-bills.R:
--------------------------------------------------------------------------------
1 | ### tidying bills datas
2 |
3 | bills_tidy <- function(df, tidy_style) {
4 | if (nrow(df) > 0) {
5 | df$date._value <- as.POSIXct(df$date._value)
6 |
7 | df$date._datatype <- "POSIXct"
8 |
9 | if ("bill" %in% names(df)) {
10 | df$bill <- gsub("http://data.parliament.uk/resources/", "", df$bill)
11 | }
12 | }
13 |
14 | df <- hansard_tidy(df, tidy_style)
15 |
16 | df
17 | }
18 |
--------------------------------------------------------------------------------
/data-raw/data-prep.R:
--------------------------------------------------------------------------------
1 |
2 | # Bill Publication Types -----------------------------------------------------------
3 |
4 |
5 |
6 | x <- bill_publications(start_date = "2015-01-01")
7 |
8 | bill_publication_types <- unique(x$publication_type_value)
9 |
10 | bill_publication_types <- bill_publication_types[!is.na(bill_publication_types)]
11 |
12 | bill_publication_types
13 |
14 | devtools::use_data(bill_publication_types, overwrite = T)
15 |
--------------------------------------------------------------------------------
/cran-comments.md:
--------------------------------------------------------------------------------
1 |
2 | # Resubmission
3 |
4 | This is an update that replaces deprecated tidyr functions used
5 | in data processing.
6 |
7 | There are no notes, warnings or errors from R CMD check.
8 |
9 | ## Test environments
10 |
11 | * Ubuntu 14.04.5 (on Travis-CI): R devel and release
12 | * local MacOS 10.14.6 installation: R 3.6.1
13 | * win-builder (devel and release)
14 |
15 |
16 | ##R CMD check results
17 | 0 errors | 0 warnings | 0 notes
18 |
--------------------------------------------------------------------------------
/docs/docsearch.json:
--------------------------------------------------------------------------------
1 | {
2 | "index_name": "hansard",
3 | "start_urls": {},
4 | "sitemap_urls": "/sitemap.xml",
5 | "selectors": {
6 | "lvl0": ".contents h1",
7 | "lvl1": ".contents h2",
8 | "lvl2": ".contents h3, .contents th, .contents dt",
9 | "lvl3": ".contents h4",
10 | "lvl4": ".contents h5",
11 | "text": ".contents p, .contents li, .usage, .template-article .contents .pre"
12 | },
13 | "selectors_exclude": ".dont-index"
14 | }
15 |
--------------------------------------------------------------------------------
/tests/testthat/test_constituencies.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("constituencies")
3 |
4 | test_that("constituencies functions return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | ctx <- hansard_constituencies(current = TRUE, verbose = TRUE)
9 | expect_length(ctx, 7)
10 | expect_true(tibble::is_tibble(ctx))
11 | expect_equal(nrow(ctx), 650)
12 | expect_true(names(ctx)[6] == "started_date_value")
13 | })
14 |
--------------------------------------------------------------------------------
/tests/testthat/test_election_candidates.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("election_candidates")
3 |
4 |
5 | test_that("election_candidates return expected format", {
6 | skip_on_cran()
7 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
8 | # skip_on_travis()
9 |
10 | xec <- hansard_election_candidates(ID = 650517, verbose = TRUE)
11 | expect_length(xec, 13)
12 | expect_type(xec, "list")
13 | expect_true(tibble::is_tibble(xec))
14 | expect_equal(nrow(xec), 10)
15 | })
16 |
--------------------------------------------------------------------------------
/R/utils-epetition.R:
--------------------------------------------------------------------------------
1 |
2 | ### tidy function for epetition_tibble
3 |
4 | epetition_tibble_tidy <- function(df, tidy_style) {
5 | if (nrow(df) > 0) {
6 | df$created._value <- gsub("T", " ", df$created._value)
7 |
8 | df$created._value <- lubridate::parse_date_time(
9 | df$created._value, "Y-m-d H:M:S"
10 | )
11 |
12 | df$created._datatype <- "POSIXct"
13 |
14 | df$status <- as.factor(df$status)
15 | }
16 |
17 | df <- hansard_tidy(df, tidy_style)
18 |
19 | df
20 | }
21 |
--------------------------------------------------------------------------------
/hansard.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 |
3 | RestoreWorkspace: Default
4 | SaveWorkspace: Default
5 | AlwaysSaveHistory: Default
6 |
7 | EnableCodeIndexing: Yes
8 | UseSpacesForTab: Yes
9 | NumSpacesForTab: 2
10 | Encoding: UTF-8
11 |
12 | RnwWeave: knitr
13 | LaTeX: XeLaTeX
14 |
15 | AutoAppendNewline: Yes
16 | StripTrailingWhitespace: Yes
17 |
18 | BuildType: Package
19 | PackageUseDevtools: Yes
20 | PackageInstallArgs: --no-multiarch --with-keep.source
21 | PackageRoxygenize: rd,collate,namespace,vignette
22 |
--------------------------------------------------------------------------------
/R/utils-constit.R:
--------------------------------------------------------------------------------
1 |
2 | ## Tidy function for constituency calls
3 |
4 | cons_tidy <- function(df, current, tidy_style) {
5 | if (nrow(df) > 0) {
6 | if (is.null(current) || current == FALSE) {
7 | df$endedDate._value <- as.POSIXct(df$endedDate._value)
8 |
9 | df$endedDate._datatype <- "POSIXct"
10 | }
11 |
12 | df$startedDate._value <- as.POSIXct(df$startedDate._value)
13 |
14 | df$startedDate._datatype <- "POSIXct"
15 |
16 | df <- hansard_tidy(df, tidy_style)
17 | }
18 |
19 | df
20 | }
21 |
--------------------------------------------------------------------------------
/tests/testthat/test_election_results.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("election_results")
3 |
4 |
5 | test_that("election_results return expected format", {
6 | skip_on_cran()
7 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
8 |
9 | elect_all_data <- hansard_election_results(
10 | ID = 382037,
11 | all_data = FALSE,
12 | verbose = TRUE
13 | )
14 | expect_length(elect_all_data, 9)
15 | expect_type(elect_all_data, "list")
16 | expect_true(tibble::is_tibble(elect_all_data))
17 | expect_true(nrow(elect_all_data) == 650)
18 | })
19 |
--------------------------------------------------------------------------------
/docs/articles/introduction_files/header-attrs-2.1/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/docs/articles/introduction_files/header-attrs-2.5/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/docs/articles/introduction_files/header-attrs-2.7/header-attrs.js:
--------------------------------------------------------------------------------
1 | // Pandoc 2.9 adds attributes on both header and div. We remove the former (to
2 | // be compatible with the behavior of Pandoc < 2.8).
3 | document.addEventListener('DOMContentLoaded', function(e) {
4 | var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
5 | var i, h, a;
6 | for (i = 0; i < hs.length; i++) {
7 | h = hs[i];
8 | if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
9 | a = h.attributes;
10 | while (a.length > 0) h.removeAttribute(a[0].name);
11 | }
12 | });
13 |
--------------------------------------------------------------------------------
/R/utils-sessions.R:
--------------------------------------------------------------------------------
1 |
2 | ## tidying sessions queries
3 | sessions_tidy <- function(df, days, tidy_style) {
4 | df$`_about` <- gsub("http://data.parliament.uk/resources/", "", df$`_about`)
5 |
6 | if (days == FALSE) {
7 | df$endDate._value <- as.POSIXct(df$endDate._value)
8 |
9 | df$startDate._value <- as.POSIXct(df$startDate._value)
10 |
11 | df$endDate._datatype <- "POSIXct"
12 |
13 | df$startDate._datatype <- "POSIXct"
14 | } else {
15 | df$date._value <- as.POSIXct(df$date._value)
16 |
17 | df$date._datatype <- "POSIXct"
18 | }
19 |
20 | df <- hansard_tidy(df, tidy_style)
21 | }
22 |
--------------------------------------------------------------------------------
/R/utils-question-query.R:
--------------------------------------------------------------------------------
1 |
2 | question_query_construction <- function(mp_id, answering_department) {
3 | if (is.null(mp_id) || is.na(mp_id)) {
4 | mp_id_query <- ""
5 | } else {
6 | mp_id_query <- utils::URLencode(
7 | paste0(
8 | "&tablingMember=http://data.parliament.uk/members/", mp_id
9 | )
10 | )
11 | }
12 |
13 | if (is.null(answering_department) || is.na(answering_department)) {
14 | json_query <- ".json?"
15 | } else {
16 | json_query <- utils::URLencode(
17 | paste0("/answeringdepartment.json?q=", answering_department)
18 | )
19 | }
20 |
21 | paste0(json_query, mp_id_query)
22 | }
23 |
--------------------------------------------------------------------------------
/_pkgdown.yml:
--------------------------------------------------------------------------------
1 | template:
2 | params:
3 | bootswatch: journal
4 | ganalytics: UA-90706059-1
5 |
6 |
7 | authors:
8 | Evan Odell:
9 | href: https://evanodell.com
10 |
11 | name:
12 | navbar:
13 | left:
14 | - text: "Docs Home"
15 | href: http://docs.evanodell.com
16 | - text: "News"
17 | href: news/index.html
18 | - text: "Reference"
19 | href: reference/index.html
20 | menu:
21 | - text: "Introduction"
22 | href: articles/introduction.html
23 | - text: "Packages"
24 | menu:
25 | - text: "Documentation Home"
26 | href: http://docs.evanodell.com
27 |
28 | right:
29 | - icon: fa-github fa-lg
30 | href: https://github.com/EvanOdell/hansard
31 | - icon: fa-home fa-lg
32 | href: http://evanodell.com
33 |
--------------------------------------------------------------------------------
/R/utils-edm-loop.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Bespoke looping function to manage the weird stuff going on
4 | # with EDM primary sponsors
5 | edm_loop_query <- function(query, verbose) {
6 | veb(verbose)
7 |
8 | jpage <- jpage_func(query)
9 |
10 | seq_list <- seq(from = 0, to = jpage, by = 1)
11 |
12 | pages <- list()
13 |
14 | for (i in seq_along(seq_list)) {
15 | mydata <- jsonlite::fromJSON(paste0(query, seq_list[[i]]), flatten = TRUE)
16 | if (verbose) {
17 | message("Retrieving page ", seq_list[[i]] + 1, " of ", jpage + 1)
18 | }
19 | mydata$result$items$primarySponsorPrinted <-
20 | as.list(mydata$result$items$primarySponsorPrinted)
21 |
22 | pages[[seq_list[[i]] + 1]] <- mydata$result$items
23 | }
24 |
25 | df <- tibble::as_tibble(dplyr::bind_rows(pages))
26 |
27 | df
28 | }
29 |
--------------------------------------------------------------------------------
/man/bill_publication_types.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/data.R
3 | \docType{data}
4 | \name{bill_publication_types}
5 | \alias{bill_publication_types}
6 | \title{A character vector of possible types of bill publications.
7 | For use with \code{\link[=bill_publications]{bill_publications()}}}
8 | \format{
9 | A character vector containing 38 elements
10 | }
11 | \usage{
12 | bill_publication_types
13 | }
14 | \description{
15 | A character vector of possible types of bill publications.
16 | For use with \code{\link[=bill_publications]{bill_publications()}}
17 | }
18 | \seealso{
19 | \code{\link[=bill_publications]{bill_publications()}}
20 |
21 | \code{\link[=bills]{bills()}}
22 |
23 | \code{\link[=bill_stage_types]{bill_stage_types()}}
24 | }
25 | \keyword{datasets}
26 |
--------------------------------------------------------------------------------
/docs/link.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
--------------------------------------------------------------------------------
/R/utils-elections.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | # elections tidying -------------------------------------------------------
4 |
5 | elections_tidy <- function(df, tidy_style) {
6 | if (nrow(df) > 0) {
7 | df$date._value <- as.POSIXct(df$date._value)
8 |
9 | df$date._datatype <- "POSIXct"
10 | }
11 |
12 | df <- hansard_tidy(df, tidy_style)
13 |
14 | df
15 | }
16 |
17 |
18 | ## election_candidates tidy function -------------------------------------
19 | elect_can_tidy <- function(df, tidy_style) {
20 | if (nrow(df) > 0) {
21 | df$election._about <- gsub(
22 | "http://data.parliament.uk/resources/",
23 | "", df$election._about
24 | )
25 |
26 | df$constituency._about <- gsub(
27 | "http://data.parliament.uk/resources/", "", df$constituency._about
28 | )
29 | }
30 |
31 | df <- hansard_tidy(df, tidy_style)
32 |
33 | df
34 | }
35 |
--------------------------------------------------------------------------------
/R/utils-hansard-tidy.R:
--------------------------------------------------------------------------------
1 |
2 | # A function to make the results of calls to the API easier to work with.
3 |
4 | hansard_tidy <- function(df, tidy_style) {
5 | if (nrow(df) > 0) {
6 | names(df) <- gsub("\\.", "_", names(df), perl = TRUE)
7 |
8 | names(df) <- gsub(
9 | "([[:lower:]])([[:upper:]])", "\\1_\\2", names(df),
10 | perl = TRUE
11 | )
12 |
13 | names(df) <- gsub("__", "_", names(df), perl = TRUE)
14 |
15 | names(df) <- gsub("^_", "", names(df), perl = TRUE)
16 |
17 | names(df) <- tolower(names(df))
18 |
19 | names(df)[names(df) == "x_about"] <- "about"
20 |
21 | names(df)[names(df) == "x_value"] <- "value"
22 |
23 | if ("about" %in% names(df)) {
24 | df$about <- gsub("http://data.parliament.uk/resources/", "", df$about)
25 | }
26 | names(df) <- snakecase::to_any_case(names(df), case = tidy_style)
27 | }
28 |
29 | df
30 | }
31 |
--------------------------------------------------------------------------------
/R/utils-research.R:
--------------------------------------------------------------------------------
1 |
2 | # Tidying research briefing retrievals
3 | research_tidy <- function(df, tidy_style) {
4 | df$date._value <- gsub("T", " ", df$date._value)
5 |
6 | df$date._value <- lubridate::parse_date_time(
7 | df$date._value,
8 | "Y-m-d H:M:Sz!*"
9 | )
10 |
11 | df$date._datatype <- "POSIXct"
12 |
13 | df$description <- as.character(df$description)
14 |
15 | names(df)[names(df) == "_about"] <- "about"
16 |
17 | df$about <- gsub("http://data.parliament.uk/resources/", "", df$about)
18 |
19 | df$description[df$description == "NULL"] <- NA
20 |
21 | seq_list <- seq(from = 1, to = nrow(df), by = 1)
22 |
23 | pages <- list()
24 |
25 | for (i in seq_along(seq_list)) {
26 | if (is.null(df$section[[seq_list[[i]]]]) == FALSE) {
27 | df$section[[seq_list[[i]]]] <- hansard_tidy(
28 | df$section[[seq_list[[i]]]],
29 | tidy_style
30 | )
31 | }
32 | }
33 |
34 | df <- hansard_tidy(df, tidy_style)
35 | }
36 |
--------------------------------------------------------------------------------
/tests/testthat/test_misc2.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("papers, publications, sessions, tv part 2")
3 |
4 | test_that("papers laid, publications, sessions, tv part 2, expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | tvclipsmp <- hansard_tv_clips(4591,
9 | start_date = "2016-01-11",
10 | end_date = "2017-01-12", verbose = TRUE
11 | )
12 | expect_length(tvclipsmp, 7)
13 | expect_type(tvclipsmp, "list")
14 | expect_true(tibble::is_tibble(tvclipsmp))
15 |
16 | chan <- hansard_tv_channels(verbose = TRUE)
17 | expect_length(chan, 3)
18 | expect_type(chan, "list")
19 | expect_true(tibble::is_tibble(chan))
20 |
21 | # gen <- hansard_generic("elections.json?")
22 | # expect_length(gen, 5)
23 | # expect_type(gen, "list")
24 | # expect_true(tibble::is_tibble(gen))
25 |
26 | sess <- hansard_sessions_info(days = FALSE, verbose = TRUE)
27 | expect_length(sess, 9)
28 | expect_type(sess, "list")
29 | expect_true(tibble::is_tibble(sess))
30 | })
31 |
--------------------------------------------------------------------------------
/R/bill_stage_types.R:
--------------------------------------------------------------------------------
1 | #' Bill Stage Types
2 | #'
3 | #' Returns a tibble with all possible bill stage types.
4 | #'
5 | #' @inheritParams all_answered_questions
6 | #' @return A tibble of bill stage types.
7 | #' @seealso [bills()]
8 | #' @seealso [bill_publications()]
9 | #' @export
10 | #' @examples
11 | #' \dontrun{
12 | #' x <- bill_stage_types()
13 | #' }
14 | #'
15 | bill_stage_types <- function(tidy = TRUE, tidy_style = "snake",
16 | verbose = TRUE) {
17 | stages <- jsonlite::fromJSON(
18 | "http://lda.data.parliament.uk/billstagetypes.json?_pageSize=100",
19 | flatten = TRUE
20 | )
21 |
22 | df <- tibble::as_tibble(stages$result$items)
23 |
24 | if (nrow(df) == 0) {
25 | message("The request did not return any data.
26 | Please check your parameters.")
27 | } else {
28 | if (tidy) {
29 | df <- hansard_tidy(df, tidy_style)
30 | }
31 |
32 | df
33 | }
34 | }
35 |
36 |
37 | #' @rdname bill_stage_types
38 | #' @export
39 | hansard_bill_stage_types <- bill_stage_types
40 |
--------------------------------------------------------------------------------
/tests/testthat/test_research_briefings.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("research_briefings")
3 |
4 |
5 | test_that("research_briefings return expected format", {
6 | skip_on_cran()
7 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
8 |
9 | rtl <- hansard_research_topics_list()
10 | expect_is(rtl, "list")
11 | # expect_length(rtl, 20)
12 |
13 | rsl <- hansard_research_subtopics_list()
14 | expect_is(rsl, "list")
15 | # expect_length(rsl, 20)
16 |
17 | rtyl <- hansard_research_types_list()
18 | expect_is(rtyl, "list")
19 | # expect_length(rtyl, 6)
20 |
21 | rbdf <- hansard_research_briefings(
22 | subtopic = "Falkland Islands",
23 | verbose = TRUE
24 | )
25 | expect_length(rbdf, 14)
26 | expect_true(tibble::is_tibble(rbdf))
27 |
28 | rbtsb <- hansard_research_briefings(
29 | topic = "Defence",
30 | subtopic = "Falkland Islands",
31 | verbose = TRUE
32 | )
33 | # expect_length(rbtsb, 14)
34 | expect_true(tibble::is_tibble(rbtsb))
35 | expect_true(rbdf[[1]][[1]] == rbtsb[[1]][[1]])
36 | })
37 |
--------------------------------------------------------------------------------
/tests/testthat/test_early_day_motions.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("early day motions")
3 |
4 | test_that("edm functions return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | # xedmid <- hansard_early_day_motions(edm_id = 1073)
9 | # expect_length(xedmid, 11)
10 | # expect_type(xedmid, "list")
11 | # expect_true(tibble::is_tibble(xedmid))
12 |
13 | xedmids <- hansard_early_day_motions(
14 | edm_id = 1073,
15 | session = "2015/16", verbose = TRUE
16 | )
17 | expect_length(xedmids, 11)
18 | expect_type(xedmids, "list")
19 | expect_true(tibble::is_tibble(xedmids))
20 | expect_equal(nrow(xedmids), 1)
21 |
22 | xedmid_full <- hansard_mp_edms(
23 | mp_id = 3967, primary_sponsor = TRUE,
24 | sponsor = FALSE, signatory = FALSE,
25 | full_data = TRUE, end_date = "2015-02-11",
26 | start_date = "2015-02-10", verbose = TRUE
27 | )
28 | expect_length(xedmid_full, 21)
29 | expect_true(tibble::is_tibble(xedmid_full))
30 | expect_equal(nrow(xedmid_full), 2)
31 | })
32 |
--------------------------------------------------------------------------------
/tests/testthat/test_epetition.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("epetitions")
3 |
4 | test_that("epetitions functions return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | epetit <- hansard_epetition(
9 | ID = 706964,
10 | by_constituency = TRUE, verbose = TRUE
11 | )
12 | expect_length(epetit, 7)
13 | expect_type(epetit, "list")
14 | expect_true(tibble::is_tibble(epetit))
15 | expect_true(nrow(epetit) == 650)
16 |
17 | epetitnocont <- hansard_epetition(
18 | ID = 706964,
19 | by_constituency = FALSE,
20 | verbose = TRUE
21 | )
22 | expect_length(epetitnocont, 13)
23 | expect_type(epetitnocont, "list")
24 | expect_true(tibble::is_tibble(epetitnocont))
25 | expect_true(nrow(epetitnocont) == 1)
26 |
27 | xepl <- hansard_epetition_tibble(
28 | start_date = "2016-02-01",
29 | end_date = "2016-03-25",
30 | max_signatures = 9, verbose = TRUE
31 | )
32 | expect_length(xepl, 8)
33 | expect_type(xepl, "list")
34 | expect_true(tibble::is_tibble(xepl))
35 | expect_true(nrow(xepl) == 73)
36 | })
37 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # MIT License
2 |
3 | Copyright (c) 2018 Evan Odell
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/tests/testthat/test_2all_answered_questions.R:
--------------------------------------------------------------------------------
1 |
2 | library(hansard)
3 | context("all_answered_questions part2")
4 |
5 | test_that("all_answered_questions return expected format", {
6 | skip_on_cran()
7 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
8 |
9 | anameid <- hansard_all_answered_questions(
10 | house = "lords", answering_body = 60,
11 | start_date = "2017-03-01",
12 | end_date = "2017-03-20",
13 | verbose = TRUE
14 | )
15 | expect_length(anameid, 31)
16 | expect_type(anameid, "list")
17 | expect_true(tibble::is_tibble(anameid))
18 | expect_equal(nrow(anameid), 38)
19 |
20 | bidname <- hansard_all_answered_questions(
21 | house = 2,
22 | answering_body = "Education",
23 | start_date = "2017-03-01",
24 | end_date = "2017-03-20",
25 | verbose = TRUE
26 | )
27 | expect_length(bidname, 31)
28 | expect_type(bidname, "list")
29 | expect_true(tibble::is_tibble(bidname))
30 | expect_equal(nrow(bidname), 38)
31 | expect_true(names(bidname[1]) == names(anameid[1]))
32 | expect_equivalent(names(bidname), names(anameid))
33 | expect_equal(nrow(bidname), nrow(anameid))
34 | })
35 |
--------------------------------------------------------------------------------
/docs/articles/introduction_files/anchor-sections-1.0/anchor-sections.js:
--------------------------------------------------------------------------------
1 | // Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020.
2 | document.addEventListener('DOMContentLoaded', function() {
3 | // Do nothing if AnchorJS is used
4 | if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) {
5 | return;
6 | }
7 |
8 | const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
9 |
10 | // Do nothing if sections are already anchored
11 | if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) {
12 | return null;
13 | }
14 |
15 | // Use section id when pandoc runs with --section-divs
16 | const section_id = function(x) {
17 | return ((x.classList.contains('section') || (x.tagName === 'SECTION'))
18 | ? x.id : '');
19 | };
20 |
21 | // Add anchors
22 | h.forEach(function(x) {
23 | const id = x.id || section_id(x.parentElement);
24 | if (id === '') {
25 | return null;
26 | }
27 | let anchor = document.createElement('a');
28 | anchor.href = '#' + id;
29 | anchor.classList = ['anchor-section'];
30 | x.classList.add('hasAnchor');
31 | x.appendChild(anchor);
32 | });
33 | });
34 |
--------------------------------------------------------------------------------
/tests/testthat/test_bills.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("bills")
3 |
4 | test_that("bills return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | xb <- hansard_bills(start_date = "2017-07-01", verbose = TRUE)
9 | expect_length(xb, 10)
10 | expect_true(tibble::is_tibble(xb))
11 |
12 | xba <- hansard_bills(
13 | amendments = TRUE, start_date = "2016-12-21",
14 | verbose = TRUE
15 | )
16 | expect_length(xba, 14)
17 | expect_true(tibble::is_tibble(xba))
18 |
19 | xbid <- hansard_bills(1719, verbose = TRUE)
20 | expect_length(xbid, 10)
21 | expect_true(tibble::is_tibble(xbid))
22 |
23 | bst <- hansard_bill_stage_types(verbose = TRUE)
24 | expect_length(bst, 7)
25 | expect_true(tibble::is_tibble(bst))
26 |
27 | bill_pubs <- bill_publications(ID = 752025)
28 | expect_length(bill_pubs, 10)
29 | expect_true(tibble::is_tibble(bill_pubs))
30 |
31 | bill_pubs_date <- bill_publications(
32 | start_date = "2018-01-01",
33 | end_date = "2018-01-12"
34 | )
35 | expect_length(bill_pubs_date, 13)
36 | expect_true(tibble::is_tibble(bill_pubs_date))
37 | expect_true(nrow(bill_pubs_date) == 86)
38 | })
39 |
--------------------------------------------------------------------------------
/tests/testthat/test_1all_answered_questions.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("all_answered_questions part1")
3 |
4 | test_that("all_answered_questions return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | aaqx <- hansard_all_answered_questions(
9 | mp_id = c(4019, 3980),
10 | answering_body = c("health", "justice"), house = "commons",
11 | start_date = "2016-12-18", end_date = "2017-01-15", verbose = TRUE
12 | )
13 | # expect_length(aaqx, 39)
14 | expect_type(aaqx, "list")
15 | expect_true(tibble::is_tibble(aaqx))
16 | expect_equal(nrow(aaqx), 165)
17 |
18 | aaq <- hansard_all_answered_questions(
19 | start_date = "2017-03-01",
20 | end_date = "2017-03-01", verbose = TRUE
21 | )
22 | # expect_length(aaq, 37)
23 | expect_type(aaq, "list")
24 | expect_true(tibble::is_tibble(aaq))
25 |
26 | xaaqda <- hansard_all_answered_questions(
27 | tabling_mp_id = 172,
28 | start_date = "2016-12-18",
29 | end_date = "2017-03-02",
30 | verbose = TRUE
31 | )
32 | # expect_length(xaaqda, 29)
33 | expect_type(xaaqda, "list")
34 | expect_true(tibble::is_tibble(xaaqda))
35 | expect_equal(nrow(xaaqda), 6)
36 | })
37 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: hansard
2 | Type: Package
3 | Title: Provides Easy Downloading Capabilities for the UK Parliament API
4 | Version: 0.8.0.9000
5 | Authors@R: person("Evan Odell", email="evanodell91@gmail.com",
6 | role=c("aut", "cre"),
7 | comment = c(ORCID='0000-0003-1845-808X'))
8 | Maintainer: Evan Odell
9 | Description: Provides functions to download data from the
10 | APIs. Because of the structure of the API,
11 | there is a named function for each type of available data for ease of use,
12 | as well as some functions designed to retrieve specific pieces of commonly
13 | used data. Functions for each new API will be added as and when they become
14 | available.
15 | URL: https://docs.evanodell.com/hansard
16 | BugReports: https://github.com/EvanOdell/hansard/issues
17 | License: MIT + file LICENSE
18 | LazyData: TRUE
19 | Depends: R(>= 3.2.0)
20 | Imports:
21 | jsonlite,
22 | dplyr,
23 | tibble,
24 | lubridate,
25 | tidyr,
26 | snakecase,
27 | httr
28 | RoxygenNote: 7.1.1
29 | Roxygen: list(markdown = TRUE)
30 | Encoding: UTF-8
31 | Suggests:
32 | knitr,
33 | rmarkdown,
34 | testthat,
35 | covr,
36 | methods
37 | VignetteBuilder: knitr
38 |
--------------------------------------------------------------------------------
/man/edm_text.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/early_day_motions.R
3 | \name{edm_text}
4 | \alias{edm_text}
5 | \title{Early Day Motion Text}
6 | \usage{
7 | edm_text(id, tidy = TRUE, tidy_style = "snake", verbose = TRUE)
8 | }
9 | \arguments{
10 | \item{id}{The ID of an individual Early Day Motion, or a vector of IDs,
11 | as found in the \code{about} column of returns from \code{\link[=early_day_motions]{early_day_motions()}}}
12 |
13 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
14 | in the tibble to remove special characters and superfluous text, and
15 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
16 |
17 | \item{tidy_style}{The style to convert variable names to, if
18 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
19 | Defaults to \code{'snake'}.}
20 |
21 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
22 | progress of the API request. Defaults to \code{TRUE}.}
23 | }
24 | \value{
25 | A tibble of containing the EDM text and its ID.
26 | }
27 | \description{
28 | A quick and dirty function for a specific use case, use with caution.
29 | }
30 | \examples{
31 | \dontrun{
32 | y <- edm_text(c("811291", "811292", "811293"))
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | # DO NOT CHANGE the "init" and "install" sections below
2 |
3 | # Download script file from GitHub
4 | init:
5 | ps: |
6 | $ErrorActionPreference = "Stop"
7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1"
8 | Import-Module '..\appveyor-tool.ps1'
9 |
10 | install:
11 | ps: Bootstrap
12 |
13 | cache:
14 | - C:\RLibrary
15 |
16 | environment:
17 | NOT_CRAN: true
18 | # env vars that may need to be set, at least temporarily, from time to time
19 | # see https://github.com/krlmlr/r-appveyor#readme for details
20 | # USE_RTOOLS: true
21 | # R_REMOTES_STANDALONE: true
22 |
23 | # Adapt as necessary starting from here
24 |
25 | build_script:
26 | - travis-tool.sh install_deps
27 |
28 | test_script:
29 | - travis-tool.sh run_tests
30 |
31 | on_failure:
32 | - 7z a failure.zip *.Rcheck\*
33 | - appveyor PushArtifact failure.zip
34 |
35 | artifacts:
36 | - path: '*.Rcheck\**\*.log'
37 | name: Logs
38 |
39 | - path: '*.Rcheck\**\*.out'
40 | name: Logs
41 |
42 | - path: '*.Rcheck\**\*.fail'
43 | name: Logs
44 |
45 | - path: '*.Rcheck\**\*.Rout'
46 | name: Logs
47 |
48 | - path: '\*_*.tar.gz'
49 | name: Bits
50 |
51 | - path: '\*_*.zip'
52 | name: Bits
53 |
--------------------------------------------------------------------------------
/man/bill_stage_types.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/bill_stage_types.R
3 | \name{bill_stage_types}
4 | \alias{bill_stage_types}
5 | \alias{hansard_bill_stage_types}
6 | \title{Bill Stage Types}
7 | \usage{
8 | bill_stage_types(tidy = TRUE, tidy_style = "snake", verbose = TRUE)
9 |
10 | hansard_bill_stage_types(tidy = TRUE, tidy_style = "snake", verbose = TRUE)
11 | }
12 | \arguments{
13 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
14 | in the tibble to remove special characters and superfluous text, and
15 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
16 |
17 | \item{tidy_style}{The style to convert variable names to, if
18 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
19 | Defaults to \code{'snake'}.}
20 |
21 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
22 | progress of the API request. Defaults to \code{TRUE}.}
23 | }
24 | \value{
25 | A tibble of bill stage types.
26 | }
27 | \description{
28 | Returns a tibble with all possible bill stage types.
29 | }
30 | \examples{
31 | \dontrun{
32 | x <- bill_stage_types()
33 | }
34 |
35 | }
36 | \seealso{
37 | \code{\link[=bills]{bills()}}
38 |
39 | \code{\link[=bill_publications]{bill_publications()}}
40 | }
41 |
--------------------------------------------------------------------------------
/tests/testthat/test_elections.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("elections")
3 |
4 |
5 | test_that("election functions return expected format", {
6 | skip_on_cran()
7 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
8 |
9 | elect <- hansard_elections(verbose = TRUE)
10 | expect_length(elect, 5)
11 | expect_type(elect, "list")
12 | expect_true(tibble::is_tibble(elect))
13 |
14 | electid <- hansard_elections(ID = 517994, verbose = TRUE)
15 | expect_length(electid, 6)
16 | expect_type(electid, "list")
17 | expect_true(tibble::is_tibble(electid))
18 | expect_equal(nrow(electid), 1)
19 |
20 | elreidperc <- hansard_election_results(
21 | ID = 517994,
22 | calculate_percent = TRUE,
23 | verbose = TRUE
24 | )
25 | expect_length(elreidperc, 11)
26 | expect_type(elreidperc, "list")
27 | expect_true(tibble::is_tibble(elreidperc))
28 |
29 | electall <- hansard_election_results(verbose = TRUE)
30 | expect_length(electall, 9)
31 | expect_type(electall, "list")
32 | expect_true(tibble::is_tibble(electall))
33 |
34 | electcons <- hansard_election_results(
35 | ID = 730039,
36 | calculate_percent = TRUE,
37 | constit_details = TRUE,
38 | verbose = TRUE
39 | )
40 | expect_length(electcons, 19)
41 | expect_type(electcons, "list")
42 | expect_true(tibble::is_tibble(electcons))
43 | expect_true(nrow(electcons) == 650)
44 | })
45 |
--------------------------------------------------------------------------------
/tests/testthat/test_members.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("members")
3 |
4 | test_that("members functions return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | # Members search
9 | # msabbot <- hansard_members_search(search = "*abbot*", verbose = TRUE)
10 | # expect_length(msabbot, 12)
11 | # expect_type(msabbot, "list")
12 | # expect_true(tibble::is_tibble(msabbot))
13 |
14 | # Lookup by member id
15 | mabbot <- hansard_members(172, verbose = TRUE)
16 | expect_length(mabbot, 13)
17 | expect_type(mabbot, "list")
18 | expect_true(tibble::is_tibble(mabbot))
19 |
20 | memempt <- hansard_members(verbose = TRUE)
21 | expect_length(memempt, 12)
22 | expect_type(memempt, "list")
23 | expect_true(tibble::is_tibble(memempt))
24 |
25 | camem <- hansard_commons_members(verbose = TRUE)
26 | expect_length(camem, 12)
27 | expect_type(camem, "list")
28 | expect_true(tibble::is_tibble(camem))
29 |
30 | lamem <- hansard_lords_members(verbose = TRUE)
31 | expect_length(lamem, 9)
32 | expect_type(lamem, "list")
33 | expect_true(tibble::is_tibble(lamem))
34 |
35 | lint <- hansard_lords_interests(530, verbose = TRUE)
36 | expect_length(lint, 8)
37 | expect_type(lint, "list")
38 | expect_true(tibble::is_tibble(lint))
39 |
40 |
41 | a <- members()
42 | b <- members_search()
43 | expect_equal(a, b)
44 | })
45 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Code of Conduct
2 |
3 | As contributors and maintainers of this project, we pledge to respect all people who
4 | contribute through reporting issues, posting feature requests, updating documentation,
5 | submitting pull requests or patches, and other activities.
6 |
7 | We are committed to making participation in this project a harassment-free experience for
8 | everyone, regardless of level of experience, gender, gender identity and expression,
9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
10 |
11 | Examples of unacceptable behavior by participants include the use of sexual language or
12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment,
13 | insults, or other unprofessional conduct.
14 |
15 | Project maintainers have the right and responsibility to remove, edit, or reject comments,
16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this
17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
18 | from the project team.
19 |
20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
21 | opening an issue or contacting one or more of the project maintainers.
22 |
23 | This Code of Conduct is adapted from the Contributor Covenant
24 | (http://contributor-covenant.org), version 1.0.0, available at
25 | http://contributor-covenant.org/version/1/0/0/
26 |
--------------------------------------------------------------------------------
/.github/workflows/test-coverage.yaml:
--------------------------------------------------------------------------------
1 | on:
2 | push:
3 | branches:
4 | - main
5 | - master
6 | pull_request:
7 | branches:
8 | - main
9 | - master
10 |
11 | name: test-coverage
12 |
13 | jobs:
14 | test-coverage:
15 | runs-on: macOS-latest
16 | env:
17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
18 | steps:
19 | - uses: actions/checkout@v2
20 |
21 | - uses: r-lib/actions/setup-r@v1
22 |
23 | - uses: r-lib/actions/setup-pandoc@v1
24 |
25 | - name: Query dependencies
26 | run: |
27 | install.packages('remotes')
28 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
29 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
30 | shell: Rscript {0}
31 |
32 | - name: Cache R packages
33 | uses: actions/cache@v2
34 | with:
35 | path: ${{ env.R_LIBS_USER }}
36 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
37 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
38 |
39 | - name: Install dependencies
40 | run: |
41 | install.packages(c("remotes"))
42 | remotes::install_deps(dependencies = TRUE)
43 | remotes::install_cran("covr")
44 | shell: Rscript {0}
45 |
46 | - name: Test coverage
47 | run: covr::codecov()
48 | shell: Rscript {0}
49 |
--------------------------------------------------------------------------------
/R/commons_division_date.R:
--------------------------------------------------------------------------------
1 | #' House of Commons Division Dates
2 | #'
3 | #' Returns a tibble with the divisions (votes) in the
4 | #' House of Commons on a given date.
5 | #'
6 | #' @param date Returns all divisions on a given date.
7 | #' Defaults to `NULL`.
8 | #'
9 | #' @param extra_args Additional parameters to pass to API.
10 | #' Defaults to `NULL`.
11 | #'
12 | #' @inheritParams all_answered_questions
13 | #'
14 | #' @return A tibble with the dates of divisions in the House of Commons.
15 | #' @export
16 | #' @examples
17 | #' \dontrun{
18 | #' # all commons divisions on 19 April 2017
19 | #' x <- commons_division_date("2017-04-19")
20 | #' }
21 | #'
22 | commons_division_date <- function(date = NULL, extra_args = NULL, tidy = TRUE,
23 | tidy_style = "snake", verbose = TRUE) {
24 | if (is.null(date)) {
25 | stop("Please include a date.", call. = FALSE)
26 | } else {
27 | date <- paste0("&date=", as.character(date))
28 |
29 | query <- paste0(url_util, "commonsdivisions.json?", date, extra_args)
30 |
31 | df <- loop_query(query, verbose) # in utils-loop.R
32 |
33 | if (nrow(df) == 0) {
34 | message("The request did not return any data.
35 | Please check your parameters.")
36 | } else {
37 | if (tidy) {
38 | df <- cdd_tidy(df, tidy_style) ## utils-commons.R
39 | }
40 |
41 | df
42 | }
43 | }
44 | }
45 |
46 | #' @rdname commons_division_date
47 | #' @export
48 | hansard_commons_division_date <- commons_division_date
49 |
--------------------------------------------------------------------------------
/tests/testthat/test_mp_misc.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("misc MP functions")
3 |
4 | test_that("members vote record, questions functions return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | mpqs <- hansard_mp_questions(c(172, 4019), "all",
9 | start_date = "2015-02-01",
10 | end_date = "2015-07-01", verbose = TRUE
11 | )
12 | expect_length(mpqs, 11)
13 | expect_type(mpqs, "list")
14 | expect_true(tibble::is_tibble(mpqs))
15 |
16 | # mpoqs <- hansard_mp_questions(172, "oral", start_date = "2015-02-01",
17 | # end_date = "2015-07-01", verbose=TRUE)
18 | # expect_length(mpoqs, 24)
19 | # expect_type(mpoqs, "list")
20 | # expect_true(tibble::is_tibble(mpoqs))
21 |
22 | mpvrall <- hansard_mp_vote_record(172,
23 | lobby = "all",
24 | start_date = "2017-01-01",
25 | end_date = "2017-03-01", verbose = TRUE
26 | )
27 | expect_length(mpvrall, 6)
28 | expect_type(mpvrall, "list")
29 | expect_true(tibble::is_tibble(mpvrall))
30 |
31 | # mpvraye <- hansard_mp_vote_record(172, lobby = "aye",
32 | # start_date = "2017-01-01", end_date = "2017-02-01", tidy = FALSE)
33 | # expect_length(mpvraye, 5)
34 | # expect_type(mpvraye, "list")
35 | # expect_true(tibble::is_tibble(mpvraye))
36 | #
37 | # mpvno <- hansard_mp_vote_record(172, lobby = "no",
38 | # start_date = "2017-01-01", end_date = "2017-02-01")
39 | # expect_length(mpvno, 6)
40 | # expect_type(mpvno, "list")
41 | # expect_true(tibble::is_tibble(mpvno))
42 | })
43 |
--------------------------------------------------------------------------------
/man/research_briefings_lists.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/research_briefings_lists.R
3 | \name{research_topics_list}
4 | \alias{research_topics_list}
5 | \alias{hansard_research_topics_list}
6 | \alias{research_subtopics_list}
7 | \alias{hansard_research_subtopics_list}
8 | \alias{research_types_list}
9 | \alias{hansard_research_types_list}
10 | \title{Lists of research briefing topics, subtopics and types.}
11 | \usage{
12 | research_topics_list()
13 |
14 | hansard_research_topics_list()
15 |
16 | research_subtopics_list()
17 |
18 | hansard_research_subtopics_list()
19 |
20 | research_types_list()
21 |
22 | hansard_research_types_list()
23 | }
24 | \value{
25 | A list with the different research topics/subtopics/types available.
26 | }
27 | \description{
28 | Returns lists of research briefing topics, subtopics and types.
29 | These functions do not accept any arguments.
30 | }
31 | \section{Member details functions}{
32 |
33 | \describe{
34 | \item{research_topics_list}{A list with the different research
35 | topics available}
36 | \item{research_subtopics_list}{A list of Parliamentary Research
37 | Briefings topics}
38 | \item{research_types_list}{A list of types of Parliamentary
39 | Research Briefings}
40 | }
41 | }
42 |
43 | \examples{
44 | \dontrun{
45 | research_topics_list <- research_topics_list()
46 |
47 | research_subtopics_list <- research_subtopics_list()
48 |
49 | research_types_list <- research_types_list()
50 | }
51 |
52 | }
53 | \seealso{
54 | \code{\link[=research_briefings]{research_briefings()}}
55 | }
56 |
--------------------------------------------------------------------------------
/R/constituencies.R:
--------------------------------------------------------------------------------
1 |
2 | #' House of Commons constituencies
3 | #'
4 | #' Imports data on House of Commons constituencies, returning a tibble of all
5 | #' current and/or former Westminster constituencies, subject to parameters.
6 | #'
7 | #' @param current If `TRUE`, returns only current constituencies. If
8 | #' `FALSE`, returns only former constituencies. If `NULL`, returns
9 | #' all current and former constituencies. Defaults to `NULL`.
10 | #' @inheritParams all_answered_questions
11 | #' @return A tibble with details of Westminster constituencies.
12 | #' @export
13 | #' @examples
14 | #' \dontrun{
15 | #' x <- constituencies()
16 | #'
17 | #' y <- constituencies(current = FALSE)
18 | #' }
19 | #'
20 | constituencies <- function(current = NULL, extra_args = NULL, tidy = TRUE,
21 | tidy_style = "snake", verbose = TRUE) {
22 | if (is.null(current)) {
23 | current_query <- ""
24 | } else if (current) {
25 | current_query <- "&exists-endedDate=false"
26 | } else if (!current) {
27 | current_query <- "&exists-endedDate=true"
28 | } else {
29 | current_query <- ""
30 | }
31 |
32 | query <- paste0(url_util, "constituencies.json?", extra_args, current_query)
33 |
34 | df <- loop_query(query, verbose) # in utils-loop.R
35 |
36 | if (nrow(df) == 0) {
37 | message("The request did not return any data.
38 | Please check your parameters.")
39 | } else {
40 | if (tidy) {
41 | df <- cons_tidy(df, current, tidy_style)
42 | }
43 |
44 | df
45 | }
46 | }
47 |
48 |
49 | #' @rdname constituencies
50 | #' @export
51 | hansard_constituencies <- constituencies
52 |
--------------------------------------------------------------------------------
/R/utils-mp-questions.R:
--------------------------------------------------------------------------------
1 |
2 | # mp_question multi function ----------------------------------------------
3 |
4 | mp_question_multi <- function(mp_id, question_type, start_date,
5 | end_date, extra_args, verbose) {
6 | mp_id_list <- as.list(mp_id)
7 |
8 | dat <- vector("list", length(mp_id_list))
9 |
10 | seq_list <- seq(from = 1, to = length(mp_id_list), by = 1)
11 |
12 | for (i in seq_along(seq_list)) {
13 | dat[[i]] <- hansard::mp_questions(
14 | mp_id = mp_id_list[[i]],
15 | question_type = question_type,
16 | end_date = end_date,
17 | start_date = start_date,
18 | extra_args = extra_args,
19 | verbose = verbose,
20 | tidy = FALSE,
21 | tidy_style = "snake"
22 | )
23 | }
24 |
25 | dat <- dat[sapply(dat, function(d) !is.null(d))]
26 |
27 | df <- dplyr::bind_rows(dat)
28 |
29 | names(df)[names(df) == "_about"] <- "about"
30 |
31 | df
32 | }
33 |
34 | ## MP question tidying
35 |
36 | mp_question_tidy <- function(df, tidy_style) {
37 | if (nrow(df) > 0) {
38 | df$dateTabled._value <- as.POSIXct(df$dateTabled._value)
39 |
40 | df$AnswerDate._value <- as.POSIXct(df$AnswerDate._value)
41 |
42 | df$AnswerDate._datatype <- "POSIXct"
43 |
44 | df$dateTabled._datatype <- "POSIXct"
45 |
46 | df$tablingMemberPrinted <- unlist(df$tablingMemberPrinted)
47 |
48 | df$AnsweringBody <- unlist(df$AnsweringBody)
49 |
50 | df$tablingMember._about <- gsub(
51 | "http://data.parliament.uk/members/", "",
52 | df$tablingMember._about
53 | )
54 | }
55 |
56 | df <- hansard_tidy(df, tidy_style)
57 |
58 | df
59 | }
60 |
--------------------------------------------------------------------------------
/R/lords_interests.R:
--------------------------------------------------------------------------------
1 |
2 | #' Peers' registered interests
3 | #'
4 | #' Registered financial interests of members of the House of Lords.
5 | #' If `peer_id=NULL` the actual details of registered interests
6 | #' are stored in a nested data frame.
7 | #'
8 | #' @param peer_id The ID of a member of the House of lords. If `NULL`,
9 | #' returns a tibble with all listed financial interests for all members.
10 | #' Defaults to `NULL`.
11 | #' @inheritParams all_answered_questions
12 | #' @return A tibble with details on the interests of peers in
13 | #' the House of Lords.
14 | #' @export
15 | #' @examples
16 | #' \dontrun{
17 | #' x <- lords_interests(4170)
18 | #'
19 | #' y <- lords_interests()
20 | #' }
21 | lords_interests <- function(peer_id = NULL, extra_args = NULL, tidy = TRUE,
22 | tidy_style = "snake", verbose = TRUE) {
23 | if (is.null(peer_id)) {
24 | json_query <- ".json?"
25 | } else {
26 | json_query <- paste0(".json?member=", peer_id)
27 | }
28 |
29 | query <- paste0(url_util, "lordsregisteredinterests", json_query, extra_args)
30 |
31 | df <- loop_query(query, verbose) # in utils-loop.R
32 |
33 | if (nrow(df) == 0) {
34 | message("The request did not return any data.
35 | Please check your parameters.")
36 | } else {
37 | if (tidy) {
38 | if (is.null(peer_id)) {
39 | df <- lords_interests_tidy2(df, tidy_style) ## in utils-lords.R
40 | } else {
41 | df <- lords_interests_tidy(df, tidy_style) ## in utils-lords.R
42 | }
43 | }
44 | df
45 | }
46 | }
47 |
48 |
49 | #' @export
50 | #' @rdname lords_interests
51 | hansard_lords_interests <- lords_interests
52 |
--------------------------------------------------------------------------------
/man/commons_division_date.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/commons_division_date.R
3 | \name{commons_division_date}
4 | \alias{commons_division_date}
5 | \alias{hansard_commons_division_date}
6 | \title{House of Commons Division Dates}
7 | \usage{
8 | commons_division_date(
9 | date = NULL,
10 | extra_args = NULL,
11 | tidy = TRUE,
12 | tidy_style = "snake",
13 | verbose = TRUE
14 | )
15 |
16 | hansard_commons_division_date(
17 | date = NULL,
18 | extra_args = NULL,
19 | tidy = TRUE,
20 | tidy_style = "snake",
21 | verbose = TRUE
22 | )
23 | }
24 | \arguments{
25 | \item{date}{Returns all divisions on a given date.
26 | Defaults to \code{NULL}.}
27 |
28 | \item{extra_args}{Additional parameters to pass to API.
29 | Defaults to \code{NULL}.}
30 |
31 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
32 | in the tibble to remove special characters and superfluous text, and
33 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
34 |
35 | \item{tidy_style}{The style to convert variable names to, if
36 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
37 | Defaults to \code{'snake'}.}
38 |
39 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
40 | progress of the API request. Defaults to \code{TRUE}.}
41 | }
42 | \value{
43 | A tibble with the dates of divisions in the House of Commons.
44 | }
45 | \description{
46 | Returns a tibble with the divisions (votes) in the
47 | House of Commons on a given date.
48 | }
49 | \examples{
50 | \dontrun{
51 | # all commons divisions on 19 April 2017
52 | x <- commons_division_date("2017-04-19")
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/tests/testthat/test_lords1.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("lords part 1 functions")
3 |
4 | test_that("lords functions return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | # Voting Records
9 | lvotesall <- hansard_lord_vote_record(530,
10 | lobby = "all",
11 | start_date = "2017-03-01",
12 | end_date = "2017-04-01",
13 | verbose = TRUE
14 | )
15 | expect_length(lvotesall, 11)
16 | expect_type(lvotesall, "list")
17 | expect_true(tibble::is_tibble(lvotesall))
18 |
19 | # lvotesnot <- hansard_lord_vote_record(530, lobby = "notcontent",
20 | # start_date = "2017-02-01", end_date = "2017-04-01")
21 | # expect_length(lvotesnot, 10)
22 | # expect_type(lvotesnot, "list")
23 | # expect_true(tibble::is_tibble(lvotesnot))
24 | #
25 | # lvotescont <- hansard_lord_vote_record(530, lobby = "content",
26 | # start_date = "2017-03-01", end_date = "2017-04-01")
27 | # expect_length(lvotescont, 10)
28 | # expect_type(lvotescont, "list")
29 | # expect_true(tibble::is_tibble(lvotescont))
30 |
31 | # Amendments
32 | lamend <- hansard_lords_amendments(
33 | decision = "Agreed",
34 | start_date = "2017-03-17",
35 | end_date = "2017-03-18", verbose = TRUE
36 | )
37 | expect_length(lamend, 29)
38 | expect_type(lamend, "list")
39 | expect_true(tibble::is_tibble(lamend))
40 | expect_equal(nrow(lamend), 28)
41 |
42 | lamendnu <- hansard_lords_amendments(
43 | decision = NULL,
44 | start_date = "2017-03-17",
45 | end_date = "2017-03-20",
46 | verbose = TRUE
47 | )
48 | expect_length(lamendnu, 29)
49 | expect_type(lamendnu, "list")
50 | expect_true(tibble::is_tibble(lamendnu))
51 | expect_equal(nrow(lamendnu), 33)
52 | })
53 |
--------------------------------------------------------------------------------
/tests/testthat/test_misc1.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("papers, publications, sessions, tv part 1")
3 |
4 | test_that("papers laid, publications, sessions, tv return expected format", {
5 | skip_on_cran()
6 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
7 |
8 | pldec <- hansard_papers_laid(
9 | withdrawn = TRUE, house = "lords",
10 | start_date = "2015-12-01",
11 | end_date = "2015-12-31", verbose = TRUE
12 | )
13 | expect_length(pldec, 16)
14 | expect_type(pldec, "list")
15 | expect_true(tibble::is_tibble(pldec))
16 | expect_equal(nrow(pldec), 11)
17 |
18 | publ <- hansard_publication_logs(683267, verbose = TRUE)
19 | expect_length(publ, 11)
20 | expect_type(publ, "list")
21 | expect_true(tibble::is_tibble(publ))
22 | expect_equal(nrow(publ), 1)
23 |
24 | publjan <- hansard_publication_logs(
25 | start_date = "2016-01-01",
26 | end_date = "2016-01-10", verbose = TRUE
27 | )
28 | expect_length(publjan, 5)
29 | expect_type(publjan, "list")
30 | expect_true(tibble::is_tibble(publjan))
31 | expect_equal(nrow(publjan), 2)
32 |
33 | publcommons <- hansard_publication_logs(
34 | house = "commons",
35 | start_date = "2016-01-01",
36 | end_date = "2016-01-15",
37 | tidy = FALSE, verbose = TRUE
38 | )
39 | expect_length(publcommons, 5)
40 | expect_type(publcommons, "list")
41 | expect_true(tibble::is_tibble(publcommons))
42 | expect_equal(nrow(publcommons), 22)
43 |
44 | # TV Programmes
45 | tvcoms <- hansard_tv_programmes("commons",
46 | start_date = "2016-12-19",
47 | end_date = "2017-01-01", verbose = TRUE
48 | )
49 | expect_length(tvcoms, 9)
50 | expect_type(tvcoms, "list")
51 | expect_true(tibble::is_tibble(tvcoms))
52 | expect_equal(nrow(tvcoms), 16)
53 | })
54 |
--------------------------------------------------------------------------------
/man/hansard.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/hansard-package.R
3 | \docType{package}
4 | \name{hansard}
5 | \alias{hansard}
6 | \title{hansard: Provides Easy Downloading Capabilities for the UK Parliament API}
7 | \description{
8 | Provides functions to request data from the data.parliament.uk APIs.
9 | Because of the structure of the data.parliament.uk API, there is a named
10 | function for each type of available data for ease of use. Functions for
11 | each new API will be added as and when they become available on
12 | . The API is rate limited to returning 5500 rows
13 | per request in some instances, though this has been inconsistent in testing.
14 | }
15 | \details{
16 | The API itself is still in beta, and only about half of the planned datasets
17 | are currently available. The package name is optimistic, as the
18 | actual contents of the Hansard are not yet available through this API.
19 |
20 | In addition to the standard function names, each function in the
21 | \code{hansard} package has a wrapper where the name is prefixed with
22 | \code{'hansard_'}. For example, both \code{bills()} and
23 | \code{hansard_bills()} will return the same result. This is because
24 | function names are taken from the specific API on
25 | \url{http://explore.data.parliament.uk/}, but they are often not very
26 | informative and could clash with functions in other packages (e.g.
27 | \code{bills()} is not a term unique to the British parliament).
28 |
29 | For more details please see the
30 | \href{https://docs.evanodell.com/hansard/articles/introduction}{vignette},
31 | or the API documentation on \url{http://explore.data.parliament.uk/}.
32 |
33 | This package is in no way officially related to or endorsed by the UK
34 | Parliamentary Data Service.
35 | }
36 |
--------------------------------------------------------------------------------
/R/utils-tv.R:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # 1st tv tidying function -------------------------------------------------
5 |
6 | tv_tidy <- function(df, tidy_style) {
7 | if (nrow(df) > 0) {
8 | df$startDate._value <- gsub(
9 | "T", " ", df$startDate._value
10 | )
11 |
12 | df$startDate._value <- lubridate::parse_date_time(
13 | df$startDate._value, "Y-m-d H:M:Sz!*"
14 | )
15 |
16 | df$startDate._datatype <- "POSIXct"
17 |
18 | df$endDate._value <- gsub(
19 | "T", " ",
20 | df$endDate._value
21 | )
22 |
23 | df$endDate._value <- lubridate::parse_date_time(
24 | df$endDate._value, "Y-m-d H:M:Sz!*"
25 | )
26 |
27 | df$endDate._datatype <- "POSIXct"
28 |
29 | df$legislature <- dplyr::bind_rows(df$legislature)
30 |
31 | df$legislature.prefLabel._value <- df$legislature$prefLabel._value
32 |
33 | df$legislature_about <- df$legislature$`_about`
34 |
35 | df$legislature_about <- gsub(
36 | "http://data.parliament.uk/terms/", "",
37 | df$legislature_about
38 | )
39 |
40 | df$legislature <- NULL
41 | }
42 |
43 | df <- hansard_tidy(df, tidy_style)
44 |
45 | df
46 | }
47 |
48 |
49 |
50 | # 2nd tv tidying function -------------------------------------------------
51 |
52 | tv_tidy2 <- function(df, mp_id, tidy_style) {
53 | if (nrow(df) > 0) {
54 | if (is.null(mp_id) == FALSE) {
55 | df <- tidyr::unnest_wider(df, "member", names_sep = "_")
56 |
57 | names(df) <- snakecase::to_any_case(names(df))
58 |
59 | df$member_label_value <- gsub(
60 | "Biography information for ", "",
61 | df$member_label_value
62 | )
63 |
64 | df$member_about <- gsub(
65 | "http://data.parliament.uk/terms/", "",
66 | df$member_about
67 | )
68 |
69 | df <- tibble::as_tibble(df)
70 | }
71 | }
72 |
73 | df <- hansard_tidy(df, tidy_style)
74 |
75 | df
76 | }
77 |
--------------------------------------------------------------------------------
/man/lords_interests.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/lords_interests.R
3 | \name{lords_interests}
4 | \alias{lords_interests}
5 | \alias{hansard_lords_interests}
6 | \title{Peers' registered interests}
7 | \usage{
8 | lords_interests(
9 | peer_id = NULL,
10 | extra_args = NULL,
11 | tidy = TRUE,
12 | tidy_style = "snake",
13 | verbose = TRUE
14 | )
15 |
16 | hansard_lords_interests(
17 | peer_id = NULL,
18 | extra_args = NULL,
19 | tidy = TRUE,
20 | tidy_style = "snake",
21 | verbose = TRUE
22 | )
23 | }
24 | \arguments{
25 | \item{peer_id}{The ID of a member of the House of lords. If \code{NULL},
26 | returns a tibble with all listed financial interests for all members.
27 | Defaults to \code{NULL}.}
28 |
29 | \item{extra_args}{Additional parameters and queries to pass to API. These
30 | queries must be strings and start with "&". See the
31 | \href{http://explore.data.parliament.uk/}{API documentation}
32 | or the package vignette for more details. Defaults to \code{NULL}.}
33 |
34 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
35 | in the tibble to remove special characters and superfluous text, and
36 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
37 |
38 | \item{tidy_style}{The style to convert variable names to, if
39 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
40 | Defaults to \code{'snake'}.}
41 |
42 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
43 | progress of the API request. Defaults to \code{TRUE}.}
44 | }
45 | \value{
46 | A tibble with details on the interests of peers in
47 | the House of Lords.
48 | }
49 | \description{
50 | Registered financial interests of members of the House of Lords.
51 | If \code{peer_id=NULL} the actual details of registered interests
52 | are stored in a nested data frame.
53 | }
54 | \examples{
55 | \dontrun{
56 | x <- lords_interests(4170)
57 |
58 | y <- lords_interests()
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/man/constituencies.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/constituencies.R
3 | \name{constituencies}
4 | \alias{constituencies}
5 | \alias{hansard_constituencies}
6 | \title{House of Commons constituencies}
7 | \usage{
8 | constituencies(
9 | current = NULL,
10 | extra_args = NULL,
11 | tidy = TRUE,
12 | tidy_style = "snake",
13 | verbose = TRUE
14 | )
15 |
16 | hansard_constituencies(
17 | current = NULL,
18 | extra_args = NULL,
19 | tidy = TRUE,
20 | tidy_style = "snake",
21 | verbose = TRUE
22 | )
23 | }
24 | \arguments{
25 | \item{current}{If \code{TRUE}, returns only current constituencies. If
26 | \code{FALSE}, returns only former constituencies. If \code{NULL}, returns
27 | all current and former constituencies. Defaults to \code{NULL}.}
28 |
29 | \item{extra_args}{Additional parameters and queries to pass to API. These
30 | queries must be strings and start with "&". See the
31 | \href{http://explore.data.parliament.uk/}{API documentation}
32 | or the package vignette for more details. Defaults to \code{NULL}.}
33 |
34 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
35 | in the tibble to remove special characters and superfluous text, and
36 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
37 |
38 | \item{tidy_style}{The style to convert variable names to, if
39 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
40 | Defaults to \code{'snake'}.}
41 |
42 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
43 | progress of the API request. Defaults to \code{TRUE}.}
44 | }
45 | \value{
46 | A tibble with details of Westminster constituencies.
47 | }
48 | \description{
49 | Imports data on House of Commons constituencies, returning a tibble of all
50 | current and/or former Westminster constituencies, subject to parameters.
51 | }
52 | \examples{
53 | \dontrun{
54 | x <- constituencies()
55 |
56 | y <- constituencies(current = FALSE)
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/R/lords_sessions.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' Lords sessions
4 | #'
5 | #' Returns the session code and other basic details for individual
6 | #' House of Lords sittings. Note that this API does not appear to have been
7 | #' updated with data after 2017-01-31.
8 | #'
9 | #'
10 | #' @param start_date Only includes sessions starting on or after this date.
11 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
12 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
13 | #' anything else that can be coerced to a date with `as.Date()`.
14 | #' Defaults to `'1900-01-01'`.
15 | #'
16 | #' @param end_date Only includes sessions ending on or before this date.
17 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
18 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
19 | #' anything else that can be coerced to a date with `as.Date()`.
20 | #' Defaults to the current system date.
21 | #' @seealso [lords_attendance_session()]
22 | #' @seealso [sessions_info()]
23 | #'
24 | #' @inheritParams all_answered_questions
25 | #' @export
26 | #' @examples
27 | #' \dontrun{
28 | #'
29 | #' a <- lords_sessions(start_date = "2017-01-01", end_date = "2017-01-31")
30 | #' }
31 | #'
32 | lords_sessions <- function(start_date = "1900-01-01", end_date = Sys.Date(),
33 | tidy = TRUE, tidy_style = "snake",
34 | verbose = TRUE) {
35 | baseurl <- paste0()
36 |
37 | dates <- paste0(
38 | "&min-date=", as.Date(start_date),
39 | "&max-date=", as.Date(end_date)
40 | )
41 |
42 | query <- paste0(url_util, "lordsattendances.json?", dates)
43 |
44 | df <- loop_query(query, verbose) # in utils-loop.R
45 |
46 | if (nrow(df) == 0) {
47 | message("The request did not return any data.
48 | Please check your parameters.")
49 | } else {
50 | if (tidy) {
51 | df <- lords_attendance_tidy(df, tidy_style)
52 | }
53 |
54 | df
55 | }
56 | }
57 |
58 |
59 |
60 | #' @rdname lords_sessions
61 | #' @export
62 | hansard_lords_sessions <- lords_sessions
63 |
--------------------------------------------------------------------------------
/.github/workflows/pr-commands.yaml:
--------------------------------------------------------------------------------
1 | on:
2 | issue_comment:
3 | types: [created]
4 | name: Commands
5 | jobs:
6 | document:
7 | if: startsWith(github.event.comment.body, '/document')
8 | name: document
9 | runs-on: macOS-latest
10 | env:
11 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
12 | steps:
13 | - uses: actions/checkout@v2
14 | - uses: r-lib/actions/pr-fetch@v1
15 | with:
16 | repo-token: ${{ secrets.GITHUB_TOKEN }}
17 | - uses: r-lib/actions/setup-r@v1
18 | - name: Install dependencies
19 | run: Rscript -e 'install.packages(c("remotes", "roxygen2"))' -e 'remotes::install_deps(dependencies = TRUE)'
20 | - name: Document
21 | run: Rscript -e 'roxygen2::roxygenise()'
22 | - name: commit
23 | run: |
24 | git config --local user.email "actions@github.com"
25 | git config --local user.name "GitHub Actions"
26 | git add man/\* NAMESPACE
27 | git commit -m 'Document'
28 | - uses: r-lib/actions/pr-push@v1
29 | with:
30 | repo-token: ${{ secrets.GITHUB_TOKEN }}
31 | style:
32 | if: startsWith(github.event.comment.body, '/style')
33 | name: style
34 | runs-on: macOS-latest
35 | env:
36 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
37 | steps:
38 | - uses: actions/checkout@v2
39 | - uses: r-lib/actions/pr-fetch@v1
40 | with:
41 | repo-token: ${{ secrets.GITHUB_TOKEN }}
42 | - uses: r-lib/actions/setup-r@v1
43 | - name: Install dependencies
44 | run: Rscript -e 'install.packages("styler")'
45 | - name: Style
46 | run: Rscript -e 'styler::style_pkg()'
47 | - name: commit
48 | run: |
49 | git config --local user.email "actions@github.com"
50 | git config --local user.name "GitHub Actions"
51 | git add \*.R
52 | git commit -m 'Style'
53 | - uses: r-lib/actions/pr-push@v1
54 | with:
55 | repo-token: ${{ secrets.GITHUB_TOKEN }}
56 |
--------------------------------------------------------------------------------
/R/hansard-package.R:
--------------------------------------------------------------------------------
1 | #' hansard: Provides Easy Downloading Capabilities for the UK Parliament API
2 | #'
3 | #' Provides functions to request data from the data.parliament.uk APIs.
4 | #' Because of the structure of the data.parliament.uk API, there is a named
5 | #' function for each type of available data for ease of use. Functions for
6 | #' each new API will be added as and when they become available on
7 | #' . The API is rate limited to returning 5500 rows
8 | #' per request in some instances, though this has been inconsistent in testing.
9 | #'
10 | #' The API itself is still in beta, and only about half of the planned datasets
11 | #' are currently available. The package name is optimistic, as the
12 | #' actual contents of the Hansard are not yet available through this API.
13 | #'
14 | #' In addition to the standard function names, each function in the
15 | #' `hansard` package has a wrapper where the name is prefixed with
16 | #' `'hansard_'`. For example, both `bills()` and
17 | #' `hansard_bills()` will return the same result. This is because
18 | #' function names are taken from the specific API on
19 | #' , but they are often not very
20 | #' informative and could clash with functions in other packages (e.g.
21 | #' `bills()` is not a term unique to the British parliament).
22 | #'
23 | #' For more details please see the
24 | #' [vignette](https://docs.evanodell.com/hansard/articles/introduction),
25 | #' or the API documentation on .
26 | #'
27 | #' This package is in no way officially related to or endorsed by the UK
28 | #' Parliamentary Data Service.
29 | #'
30 | #' @docType package
31 | #' @name hansard
32 | #' @importFrom jsonlite fromJSON
33 | #' @importFrom dplyr left_join bind_rows grouped_df summarise_all distinct
34 | #' summarise group_by_at n
35 | #' @importFrom tibble as_tibble
36 | #' @importFrom tidyr spread unnest unnest_wider
37 | #' @importFrom lubridate parse_date_time
38 | #' @importFrom snakecase to_any_case
39 | #' @importFrom httr content GET status_code http_type
40 | NULL
41 |
--------------------------------------------------------------------------------
/docs/bootstrap-toc.css:
--------------------------------------------------------------------------------
1 | /*!
2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/)
3 | * Copyright 2015 Aidan Feldman
4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */
5 |
6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */
7 |
8 | /* All levels of nav */
9 | nav[data-toggle='toc'] .nav > li > a {
10 | display: block;
11 | padding: 4px 20px;
12 | font-size: 13px;
13 | font-weight: 500;
14 | color: #767676;
15 | }
16 | nav[data-toggle='toc'] .nav > li > a:hover,
17 | nav[data-toggle='toc'] .nav > li > a:focus {
18 | padding-left: 19px;
19 | color: #563d7c;
20 | text-decoration: none;
21 | background-color: transparent;
22 | border-left: 1px solid #563d7c;
23 | }
24 | nav[data-toggle='toc'] .nav > .active > a,
25 | nav[data-toggle='toc'] .nav > .active:hover > a,
26 | nav[data-toggle='toc'] .nav > .active:focus > a {
27 | padding-left: 18px;
28 | font-weight: bold;
29 | color: #563d7c;
30 | background-color: transparent;
31 | border-left: 2px solid #563d7c;
32 | }
33 |
34 | /* Nav: second level (shown on .active) */
35 | nav[data-toggle='toc'] .nav .nav {
36 | display: none; /* Hide by default, but at >768px, show it */
37 | padding-bottom: 10px;
38 | }
39 | nav[data-toggle='toc'] .nav .nav > li > a {
40 | padding-top: 1px;
41 | padding-bottom: 1px;
42 | padding-left: 30px;
43 | font-size: 12px;
44 | font-weight: normal;
45 | }
46 | nav[data-toggle='toc'] .nav .nav > li > a:hover,
47 | nav[data-toggle='toc'] .nav .nav > li > a:focus {
48 | padding-left: 29px;
49 | }
50 | nav[data-toggle='toc'] .nav .nav > .active > a,
51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a,
52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a {
53 | padding-left: 28px;
54 | font-weight: 500;
55 | }
56 |
57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */
58 | nav[data-toggle='toc'] .nav > .active > ul {
59 | display: block;
60 | }
61 |
--------------------------------------------------------------------------------
/man/commons_terms.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/commons_terms.R
3 | \name{commons_terms}
4 | \alias{commons_terms}
5 | \alias{hansard_commons_terms}
6 | \title{Parliamentary Thesaurus}
7 | \usage{
8 | commons_terms(
9 | search = NULL,
10 | class = NULL,
11 | extra_args = NULL,
12 | tidy = TRUE,
13 | tidy_style = "snake",
14 | verbose = TRUE
15 | )
16 |
17 | hansard_commons_terms(
18 | search = NULL,
19 | class = NULL,
20 | extra_args = NULL,
21 | tidy = TRUE,
22 | tidy_style = "snake",
23 | verbose = TRUE
24 | )
25 | }
26 | \arguments{
27 | \item{search}{A string to search the parliamentary thesaurus for.}
28 |
29 | \item{class}{The class of definition to be returned Accepts one of
30 | \code{'ID'}, \code{'ORG'}, \code{'SIT'}, \code{'NAME'}, \code{'LEG'},
31 | \code{'CTP'}, \code{'PBT'} and \code{'TPG'}. Defaults to \code{NULL}.}
32 |
33 | \item{extra_args}{Additional parameters and queries to pass to API. These
34 | queries must be strings and start with "&". See the
35 | \href{http://explore.data.parliament.uk/}{API documentation}
36 | or the package vignette for more details. Defaults to \code{NULL}.}
37 |
38 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
39 | in the tibble to remove special characters and superfluous text, and
40 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
41 |
42 | \item{tidy_style}{The style to convert variable names to, if
43 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
44 | Defaults to \code{'snake'}.}
45 |
46 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
47 | progress of the API request. Defaults to \code{TRUE}.}
48 | }
49 | \value{
50 | A tibble with results from the parliamentary thesaurus.
51 | }
52 | \description{
53 | Imports the parliamentary thesaurus. The API is rate limited to 5500
54 | requests at a time, so some use of parameters is required.
55 | }
56 | \examples{
57 | \dontrun{
58 | x <- commons_terms(search = "estate")
59 |
60 | x <- commons_terms(search = "estate", class = "ORG")
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/man/lords_attendance_date.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/lords_attendance_date.R
3 | \name{lords_attendance_date}
4 | \alias{lords_attendance_date}
5 | \alias{hansard_lords_attendance_date}
6 | \title{House of Lords attendance by date}
7 | \usage{
8 | lords_attendance_date(
9 | date = NULL,
10 | tidy = TRUE,
11 | tidy_style = "snake",
12 | verbose = TRUE
13 | )
14 |
15 | hansard_lords_attendance_date(
16 | date = NULL,
17 | tidy = TRUE,
18 | tidy_style = "snake",
19 | verbose = TRUE
20 | )
21 | }
22 | \arguments{
23 | \item{date}{Accepts a date to return attendance data for. Accepts
24 | character values in \code{'YYYY-MM-DD'} format, and objects of
25 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
26 | anything else that can be coerced to a date with \code{as.Date()}.
27 | Defaults to \code{NULL}.}
28 |
29 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
30 | in the tibble to remove special characters and superfluous text, and
31 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
32 |
33 | \item{tidy_style}{The style to convert variable names to, if
34 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
35 | Defaults to \code{'snake'}.}
36 |
37 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
38 | progress of the API request. Defaults to \code{TRUE}.}
39 | }
40 | \value{
41 | A tibble with details on the lords who attended on a given date.
42 | }
43 | \description{
44 | Imports data on House of Lords attendance on a given date.
45 | }
46 | \details{
47 | Please note that House of Lords attendance data is not as
48 | tidy as some of the others that are accessible through this
49 | API, and so additional work on the return from the API may be required.
50 |
51 | Also note that this API does not appear to have been
52 | updated with data after 2017-01-31.
53 | }
54 | \examples{
55 | \dontrun{
56 | x <- lords_attendance_date(date = "2016-03-01")
57 | }
58 |
59 | }
60 | \seealso{
61 | \code{\link[=lords_attendance_session]{lords_attendance_session()}}
62 | }
63 |
--------------------------------------------------------------------------------
/man/members_search.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/members_search.R
3 | \name{members_search}
4 | \alias{members_search}
5 | \alias{hansard_members_search}
6 | \title{Search for an MP or Peer by name and constituency}
7 | \usage{
8 | members_search(
9 | search = NULL,
10 | tidy = TRUE,
11 | tidy_style = "snake",
12 | verbose = TRUE
13 | )
14 |
15 | hansard_members_search(
16 | search = NULL,
17 | tidy = TRUE,
18 | tidy_style = "snake",
19 | verbose = TRUE
20 | )
21 | }
22 | \arguments{
23 | \item{search}{Accepts any lucene query string, using * as a multiple
24 | character wildcard, and ? as the single character wildcard. Searchs are
25 | not case sensitive. If \code{NULL}, returns a tibble with all members of
26 | both houses of parliament. Defaults to \code{NULL}.}
27 |
28 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
29 | in the tibble to remove special characters and superfluous text, and
30 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
31 |
32 | \item{tidy_style}{The style to convert variable names to, if
33 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
34 | Defaults to \code{'snake'}.}
35 |
36 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
37 | progress of the API request. Defaults to \code{TRUE}.}
38 | }
39 | \value{
40 | A tibble with the results of the search.
41 | }
42 | \description{
43 | Note that there are problems with the remote endpoint for this
44 | API, and that correct search queries may not return any results.
45 | }
46 | \details{
47 | Function searches for the string and returns a tibble with all matches from
48 | both houses of parliament. Returns all partial matches in the members'
49 | names, constituencies, twitter handle and webpage. The default search is
50 | \code{NULL}, which returns a tibble of all members of both houses, the
51 | same result as \code{members()}.
52 | }
53 | \examples{
54 | \dontrun{
55 | x <- members_search("*chris*")
56 |
57 | x <- members_search(search = "*chris*")
58 | }
59 |
60 | }
61 | \seealso{
62 | \code{\link[=members]{members()}}
63 | }
64 |
--------------------------------------------------------------------------------
/tests/testthat/test_lords2.R:
--------------------------------------------------------------------------------
1 | library(hansard)
2 | context("lords part 2 functions")
3 |
4 |
5 | test_that("lords functions return expected format", {
6 | skip_on_cran()
7 | skip_if(Sys.getenv(x = "TRAVIS_R_VERSION_STRING") == "devel")
8 |
9 | # Divisions
10 | ldivsum <- hansard_lords_divisions(
11 | division_id = 705891, summary = TRUE,
12 | tidy = TRUE, verbose = TRUE
13 | )
14 | expect_length(ldivsum, 11)
15 | expect_type(ldivsum, "list")
16 | expect_true(tibble::is_tibble(ldivsum))
17 |
18 | ldiv <- hansard_lords_divisions(
19 | division_id = 705891, summary = FALSE,
20 | tidy = TRUE, verbose = TRUE
21 | )
22 | expect_length(ldiv, 19)
23 | expect_type(ldiv, "list")
24 | expect_true(tibble::is_tibble(ldiv))
25 | expect_equal(nrow(ldiv), 466)
26 |
27 | ldivdec <- hansard_lords_divisions(
28 | division_id = NULL, FALSE,
29 | start_date = "2016-12-01",
30 | end_date = "2016-12-31", verbose = TRUE
31 | )
32 | expect_length(ldivdec, 5)
33 | expect_type(ldivdec, "list")
34 | expect_true(tibble::is_tibble(ldivdec))
35 |
36 | # Written Questions
37 | lwq <- hansard_lords_written_questions(
38 | peer_id = c(3526, 4176), answering_department = c("cabinet", "Transport"),
39 | start_date = "2017-01-01", end_date = "2017-08-19", verbose = TRUE
40 | )
41 | expect_length(lwq, 12)
42 | expect_type(lwq, "list")
43 | expect_true(tibble::is_tibble(lwq))
44 | expect_equal(nrow(lwq), 48)
45 |
46 | # Attendance
47 | lasess <- hansard_lords_attendance_session(
48 | session_id = 706178,
49 | verbose = TRUE
50 | )
51 | expect_length(lasess, 8)
52 | expect_type(lasess, "list")
53 | expect_true(tibble::is_tibble(lasess))
54 |
55 | ladate <- hansard_lords_attendance_date(
56 | date = "2016-03-01",
57 | verbose = TRUE
58 | )
59 | expect_length(ladate, 6)
60 | expect_type(ladate, "list")
61 | expect_true(tibble::is_tibble(ladate))
62 |
63 |
64 | lord_sessions <- lords_sessions(
65 | start_date = "2017-01-01",
66 | end_date = "2017-01-31"
67 | )
68 | expect_length(lord_sessions, 4)
69 | expect_type(lord_sessions, "list")
70 | expect_true(tibble::is_tibble(lord_sessions))
71 | expect_true(nrow(lord_sessions) == 15)
72 | })
73 |
--------------------------------------------------------------------------------
/R/lords_attendance_date.R:
--------------------------------------------------------------------------------
1 |
2 | #' House of Lords attendance by date
3 | #'
4 | #' Imports data on House of Lords attendance on a given date.
5 | #'
6 | #' Please note that House of Lords attendance data is not as
7 | #' tidy as some of the others that are accessible through this
8 | #' API, and so additional work on the return from the API may be required.
9 | #'
10 | #' Also note that this API does not appear to have been
11 | #' updated with data after 2017-01-31.
12 | #'
13 | #'
14 | #' @param date Accepts a date to return attendance data for. Accepts
15 | #' character values in `'YYYY-MM-DD'` format, and objects of
16 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
17 | #' anything else that can be coerced to a date with `as.Date()`.
18 | #' Defaults to `NULL`.
19 |
20 | #' @inheritParams all_answered_questions
21 | #' @return A tibble with details on the lords who attended on a given date.
22 | #' @export
23 | #' @seealso [lords_attendance_session()]
24 | #' @examples
25 | #' \dontrun{
26 | #' x <- lords_attendance_date(date = "2016-03-01")
27 | #' }
28 | #'
29 | lords_attendance_date <- function(date = NULL, tidy = TRUE,
30 | tidy_style = "snake", verbose = TRUE) {
31 | if (is.null(date)) {
32 | stop("Please include a date.", call. = FALSE)
33 | }
34 |
35 | date_query <- as.Date(date)
36 |
37 | veb(verbose)
38 |
39 | attend <- jsonlite::fromJSON(
40 | paste0(url_util, "lordsattendances/date/", date_query, ".json"),
41 | flatten = TRUE
42 | )
43 |
44 | df <- tibble::as_tibble(as.data.frame(attend$result$items$attendee))
45 |
46 | df <- tidyr::unnest(df, "member")
47 |
48 | if (nrow(df) == 0) {
49 | message("The request did not return any data.
50 | Please check your parameters.")
51 | } else {
52 | if (tidy) {
53 | names(df)[names(df) == "X_about"] <- "about"
54 |
55 | names(df)[names(df) == "_about"] <- "peer_id"
56 |
57 | df$peer_id <- gsub(
58 | "http://data.parliament.uk/members/", "",
59 | df$peer_id
60 | )
61 |
62 | df <- hansard_tidy(df, tidy_style)
63 | }
64 |
65 | df
66 | }
67 | }
68 |
69 |
70 | #' @rdname lords_attendance_date
71 | #' @export
72 | hansard_lords_attendance_date <- lords_attendance_date
73 |
--------------------------------------------------------------------------------
/man/epetition.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/epetition.R
3 | \name{epetition}
4 | \alias{epetition}
5 | \alias{hansard_epetition}
6 | \title{Individual epetitions}
7 | \usage{
8 | epetition(
9 | ID = NULL,
10 | by_constituency = FALSE,
11 | extra_args = NULL,
12 | tidy = TRUE,
13 | tidy_style = "snake",
14 | verbose = TRUE
15 | )
16 |
17 | hansard_epetition(
18 | ID = NULL,
19 | by_constituency = FALSE,
20 | extra_args = NULL,
21 | tidy = TRUE,
22 | tidy_style = "snake",
23 | verbose = TRUE
24 | )
25 | }
26 | \arguments{
27 | \item{ID}{The ID of a given petition. If \code{NULL}, returns all
28 | epetitions. Defaults to \code{NULL}. See \code{\link[=epetition_tibble]{epetition_tibble()}}
29 | for a greater degree of flexibility when querying all epetitions.}
30 |
31 | \item{by_constituency}{Accepts either \code{TRUE} or \code{FALSE}.
32 | If \code{TRUE}, provides a tibble with a breakdown of signatures for
33 | each petition, by constituency. Defaults to \code{FALSE}.}
34 |
35 | \item{extra_args}{Additional parameters and queries to pass to API. These
36 | queries must be strings and start with "&". See the
37 | \href{http://explore.data.parliament.uk/}{API documentation}
38 | or the package vignette for more details. Defaults to \code{NULL}.}
39 |
40 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
41 | in the tibble to remove special characters and superfluous text, and
42 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
43 |
44 | \item{tidy_style}{The style to convert variable names to, if
45 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
46 | Defaults to \code{'snake'}.}
47 |
48 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
49 | progress of the API request. Defaults to \code{TRUE}.}
50 | }
51 | \value{
52 | A tibble with details on electronic petitions
53 | submitted to parliament.
54 | }
55 | \description{
56 | Imports data on a given epetition. For bulk epetion data,
57 | see \code{\link[=epetition_tibble]{epetition_tibble()}}.
58 | }
59 | \examples{
60 | \dontrun{
61 | x <- epetition(ID = 706964, by_constituency = TRUE)
62 | }
63 |
64 | }
65 | \seealso{
66 | \code{\link[=epetition_tibble]{epetition_tibble()}}
67 | }
68 |
--------------------------------------------------------------------------------
/man/lords_sessions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/lords_sessions.R
3 | \name{lords_sessions}
4 | \alias{lords_sessions}
5 | \alias{hansard_lords_sessions}
6 | \title{Lords sessions}
7 | \usage{
8 | lords_sessions(
9 | start_date = "1900-01-01",
10 | end_date = Sys.Date(),
11 | tidy = TRUE,
12 | tidy_style = "snake",
13 | verbose = TRUE
14 | )
15 |
16 | hansard_lords_sessions(
17 | start_date = "1900-01-01",
18 | end_date = Sys.Date(),
19 | tidy = TRUE,
20 | tidy_style = "snake",
21 | verbose = TRUE
22 | )
23 | }
24 | \arguments{
25 | \item{start_date}{Only includes sessions starting on or after this date.
26 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
27 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
28 | anything else that can be coerced to a date with \code{as.Date()}.
29 | Defaults to \code{'1900-01-01'}.}
30 |
31 | \item{end_date}{Only includes sessions ending on or before this date.
32 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
33 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
34 | anything else that can be coerced to a date with \code{as.Date()}.
35 | Defaults to the current system date.}
36 |
37 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
38 | in the tibble to remove special characters and superfluous text, and
39 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
40 |
41 | \item{tidy_style}{The style to convert variable names to, if
42 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
43 | Defaults to \code{'snake'}.}
44 |
45 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
46 | progress of the API request. Defaults to \code{TRUE}.}
47 | }
48 | \description{
49 | Returns the session code and other basic details for individual
50 | House of Lords sittings. Note that this API does not appear to have been
51 | updated with data after 2017-01-31.
52 | }
53 | \examples{
54 | \dontrun{
55 |
56 | a <- lords_sessions(start_date = "2017-01-01", end_date = "2017-01-31")
57 | }
58 |
59 | }
60 | \seealso{
61 | \code{\link[=lords_attendance_session]{lords_attendance_session()}}
62 |
63 | \code{\link[=sessions_info]{sessions_info()}}
64 | }
65 |
--------------------------------------------------------------------------------
/R/commons_terms.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' Parliamentary Thesaurus
4 | #'
5 | #' Imports the parliamentary thesaurus. The API is rate limited to 5500
6 | #' requests at a time, so some use of parameters is required.
7 | #'
8 | #' @param search A string to search the parliamentary thesaurus for.
9 | #'
10 | #' @param class The class of definition to be returned Accepts one of
11 | #' `'ID'`, `'ORG'`, `'SIT'`, `'NAME'`, `'LEG'`,
12 | #' `'CTP'`, `'PBT'` and `'TPG'`. Defaults to `NULL`.
13 | #' @inheritParams all_answered_questions
14 | #' @return A tibble with results from the parliamentary thesaurus.
15 | #' @export
16 | #' @examples
17 | #' \dontrun{
18 | #' x <- commons_terms(search = "estate")
19 | #'
20 | #' x <- commons_terms(search = "estate", class = "ORG")
21 | #' }
22 | #'
23 | commons_terms <- function(search = NULL, class = NULL, extra_args = NULL,
24 | tidy = TRUE, tidy_style = "snake",
25 | verbose = TRUE) {
26 | warning("Search functions are not consistently working on the API")
27 |
28 | if (!is.null(search)) {
29 | search_query <- paste0("&_search=", utils::URLencode(search))
30 | } else {
31 | search_query <- NULL
32 | }
33 |
34 | if (!is.null(class)) {
35 | class_list <- list(
36 | "ID", "ORG", "SIT", "NAME", "LEG",
37 | "CTP", "PBT", "TPG"
38 | )
39 |
40 | if (!(class %in% class_list)) {
41 | stop("Please check your class parameter.
42 | It must be one of \"ID\", \"ORG\", \"SIT\", \"NAME\",
43 | \"LEG\", \"CTP\", \"PBT\" or\"TPG\"", call. = FALSE)
44 | } else {
45 | class_query <- paste0("&class=", class)
46 | }
47 | } else {
48 | class_query <- NULL
49 | }
50 |
51 | if (verbose) {
52 | message("Connecting to API")
53 | }
54 |
55 | query <- paste0(
56 | url_util, "terms.json?&_view=description", search_query, class_query,
57 | extra_args
58 | )
59 |
60 | df <- loop_query(query, verbose) # in utils-loop.R
61 |
62 | if (nrow(df) == 0) {
63 | message("The request did not return any data.
64 | Please check your parameters.")
65 | } else {
66 | if (tidy) {
67 | df <- hansard_tidy(df, tidy_style)
68 | }
69 |
70 | df
71 | }
72 | }
73 |
74 |
75 | #' @rdname commons_terms
76 | #' @export
77 | hansard_commons_terms <- commons_terms
78 |
--------------------------------------------------------------------------------
/R/members_search.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' Search for an MP or Peer by name and constituency
4 | #'
5 | #' Note that there are problems with the remote endpoint for this
6 | #' API, and that correct search queries may not return any results.
7 | #'
8 | #' Function searches for the string and returns a tibble with all matches from
9 | #' both houses of parliament. Returns all partial matches in the members'
10 | #' names, constituencies, twitter handle and webpage. The default search is
11 | #' `NULL`, which returns a tibble of all members of both houses, the
12 | #' same result as `members()`.
13 | #'
14 | #'
15 | #' @param search Accepts any lucene query string, using * as a multiple
16 | #' character wildcard, and ? as the single character wildcard. Searchs are
17 | #' not case sensitive. If `NULL`, returns a tibble with all members of
18 | #' both houses of parliament. Defaults to `NULL`.
19 | #'
20 | #' @inheritParams all_answered_questions
21 | #' @return A tibble with the results of the search.
22 | #' @seealso [members()]
23 | #' @export
24 | #' @examples
25 | #' \dontrun{
26 | #' x <- members_search("*chris*")
27 | #'
28 | #' x <- members_search(search = "*chris*")
29 | #' }
30 | #'
31 | members_search <- function(search = NULL, tidy = TRUE,
32 | tidy_style = "snake", verbose = TRUE) {
33 | if (is.null(search)) {
34 | df <- members(tidy = tidy, tidy_style = tidy_style, verbose = verbose)
35 |
36 | df
37 | } else {
38 | warning("Search functions are not consistently working on the API")
39 |
40 | search <- utils::URLencode(search)
41 |
42 | veb(verbose)
43 |
44 | query <- paste0(url_util, "members.json?_search=", search)
45 |
46 | results <- jsonlite::fromJSON(query)
47 |
48 | df <- loop_query(query, verbose) # in utils-loop.R
49 |
50 | if (nrow(df) == 0) {
51 | message("The request did not return any data.
52 | Please check your parameters.")
53 | } else {
54 | if (tidy) {
55 | names(df)[names(df) == "_about"] <- "mnis_id"
56 |
57 | df$mnis_id <- gsub(
58 | "http://data.parliament.uk/members/", "", df$mnis_id
59 | )
60 |
61 | df <- hansard_tidy(df, tidy_style)
62 | }
63 |
64 | df
65 | }
66 | }
67 | }
68 |
69 | #' @rdname members_search
70 | #' @export
71 | hansard_members_search <- members_search
72 |
--------------------------------------------------------------------------------
/docs/docsearch.js:
--------------------------------------------------------------------------------
1 | $(function() {
2 |
3 | // register a handler to move the focus to the search bar
4 | // upon pressing shift + "/" (i.e. "?")
5 | $(document).on('keydown', function(e) {
6 | if (e.shiftKey && e.keyCode == 191) {
7 | e.preventDefault();
8 | $("#search-input").focus();
9 | }
10 | });
11 |
12 | $(document).ready(function() {
13 | // do keyword highlighting
14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */
15 | var mark = function() {
16 |
17 | var referrer = document.URL ;
18 | var paramKey = "q" ;
19 |
20 | if (referrer.indexOf("?") !== -1) {
21 | var qs = referrer.substr(referrer.indexOf('?') + 1);
22 | var qs_noanchor = qs.split('#')[0];
23 | var qsa = qs_noanchor.split('&');
24 | var keyword = "";
25 |
26 | for (var i = 0; i < qsa.length; i++) {
27 | var currentParam = qsa[i].split('=');
28 |
29 | if (currentParam.length !== 2) {
30 | continue;
31 | }
32 |
33 | if (currentParam[0] == paramKey) {
34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20"));
35 | }
36 | }
37 |
38 | if (keyword !== "") {
39 | $(".contents").unmark({
40 | done: function() {
41 | $(".contents").mark(keyword);
42 | }
43 | });
44 | }
45 | }
46 | };
47 |
48 | mark();
49 | });
50 | });
51 |
52 | /* Search term highlighting ------------------------------*/
53 |
54 | function matchedWords(hit) {
55 | var words = [];
56 |
57 | var hierarchy = hit._highlightResult.hierarchy;
58 | // loop to fetch from lvl0, lvl1, etc.
59 | for (var idx in hierarchy) {
60 | words = words.concat(hierarchy[idx].matchedWords);
61 | }
62 |
63 | var content = hit._highlightResult.content;
64 | if (content) {
65 | words = words.concat(content.matchedWords);
66 | }
67 |
68 | // return unique words
69 | var words_uniq = [...new Set(words)];
70 | return words_uniq;
71 | }
72 |
73 | function updateHitURL(hit) {
74 |
75 | var words = matchedWords(hit);
76 | var url = "";
77 |
78 | if (hit.anchor) {
79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor;
80 | } else {
81 | url = hit.url + '?q=' + escape(words.join(" "));
82 | }
83 |
84 | return url;
85 | }
86 |
--------------------------------------------------------------------------------
/R/utils-loop.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Retrieves data from the API, using pagination
4 | loop_query <- function(query, verbose) {
5 | veb(verbose)
6 |
7 | jpage <- jpage_func(query)
8 |
9 | seq_list <- seq(from = 0, to = jpage, by = 1)
10 |
11 | pages <- list()
12 |
13 | for (i in seq_along(seq_list)) {
14 |
15 | api_get <- httr::GET(paste0(query, "&_pageSize=100&_page=", seq_list[[i]]))
16 |
17 | if (httr::http_type(api_get) != "application/json") {
18 |
19 | stop("API did not return data in required JSON format", call. = FALSE)
20 |
21 | } else if (httr::status_code(api_get) != "200") {
22 |
23 | stop(paste("Request returned error code:", httr::status_code(api_get)),
24 | call. = FALSE
25 | )
26 |
27 | } else {
28 | mydata <- jsonlite::fromJSON(
29 | httr::content(api_get, as = "text", encoding = "utf8"),
30 | flatten = TRUE
31 | )
32 | if (verbose) {
33 | message("Retrieving page ", seq_list[[i]] + 1, " of ", jpage + 1)
34 | }
35 | pages[[seq_list[[i]] + 1]] <- mydata$result$items
36 | }
37 | }
38 | tibble::as_tibble(dplyr::bind_rows(pages))
39 | }
40 |
41 |
42 |
43 | # Special all_answered_questions loop query
44 | loop_query_aaq <- function(query, verbose) {
45 | veb(verbose)
46 |
47 | jpage <- jpage_func(query)
48 |
49 | seq_list <- seq(from = 0, to = jpage, by = 1)
50 |
51 | pages <- list()
52 |
53 | for (i in seq_along(seq_list)) {
54 | api_get <- httr::GET(paste0(query, "&_pageSize=100&_page=", seq_list[[i]]))
55 | if (httr::http_type(api_get) != "application/json") {
56 |
57 | stop("API did not return data in required JSON format", call. = FALSE)
58 |
59 | } else if (httr::status_code(api_get) != "200") {
60 |
61 | stop(paste("Request returned error code:", httr::status_code(api_get)),
62 | call. = FALSE
63 | )
64 |
65 | } else {
66 |
67 | mydata <- jsonlite::fromJSON(
68 | httr::content(api_get, as = "text", encoding = "utf8"),
69 | flatten = TRUE
70 | )
71 | if (verbose) {
72 | message("Retrieving page ", seq_list[[i]] + 1, " of ", jpage + 1)
73 | }
74 | mydata$result$items$answer.previousAnswerVersion.answeringMember <- NULL
75 |
76 | pages[[seq_list[[i]] + 1]] <- mydata$result$items
77 |
78 | }
79 | }
80 | tibble::as_tibble(dplyr::bind_rows(pages))
81 | }
82 |
--------------------------------------------------------------------------------
/man/election_candidates.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/election_candidates.R
3 | \name{election_candidates}
4 | \alias{election_candidates}
5 | \alias{hansard_election_candidates}
6 | \title{Election candidate details}
7 | \usage{
8 | election_candidates(
9 | ID = NULL,
10 | constit_details = FALSE,
11 | extra_args = NULL,
12 | tidy = TRUE,
13 | tidy_style = "snake",
14 | verbose = TRUE
15 | )
16 |
17 | hansard_election_candidates(
18 | ID = NULL,
19 | constit_details = FALSE,
20 | extra_args = NULL,
21 | tidy = TRUE,
22 | tidy_style = "snake",
23 | verbose = TRUE
24 | )
25 | }
26 | \arguments{
27 | \item{ID}{Accepts an ID for a general or by-election from the 2010 General
28 | Election onwards, and returns the results. If \code{NULL}, returns all
29 | available election results. Defaults to \code{NULL}.}
30 |
31 | \item{constit_details}{If \code{TRUE}, returns additional details on each
32 | constituency, including its GSS (Government Statistical Service) code.
33 | Defaults to \code{FALSE}.}
34 |
35 | \item{extra_args}{Additional parameters and queries to pass to API. These
36 | queries must be strings and start with "&". See the
37 | \href{http://explore.data.parliament.uk/}{API documentation}
38 | or the package vignette for more details. Defaults to \code{NULL}.}
39 |
40 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
41 | in the tibble to remove special characters and superfluous text, and
42 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
43 |
44 | \item{tidy_style}{The style to convert variable names to, if
45 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
46 | Defaults to \code{'snake'}.}
47 |
48 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
49 | progress of the API request. Defaults to \code{TRUE}.}
50 | }
51 | \description{
52 | Returns the name and party of all candidates standing in an election, for
53 | each constituency. Note that for general elections this can return a very
54 | large tibble with hundreds of variables.
55 | }
56 | \examples{
57 | \dontrun{
58 | x <- election_candidates(ID = 382037)
59 |
60 | y <- election_candidates()
61 |
62 | z <- election_candidates(constit_details = TRUE)
63 | }
64 |
65 | }
66 | \seealso{
67 | \code{\link[=elections]{elections()}}
68 |
69 | \code{\link[=election_results]{election_results()}}
70 | }
71 |
--------------------------------------------------------------------------------
/R/lords_amendments.R:
--------------------------------------------------------------------------------
1 |
2 | #' House of Lords Amendments.
3 | #'
4 | #' Returns a tibble with all available House of Lords amendments, subject
5 | #' to parameters.
6 | #'
7 | #' @param decision The decision on the amendments. Accepts one of
8 | #' `'Withdrawn'`, `'Agreed'`, `'Disagreed'`, `'Pending'`,
9 | #' `'NotMoved'`, `'Disposed'`. This parameter is not case sensitive.
10 | #' Defaults to `NULL`.
11 | #'
12 | #' @param start_date Only includes amendments to bills introduced on or after
13 | #' this date. Accepts character values in `'YYYY-MM-DD'` format, and
14 | #' objects of class `Date`, `POSIXt`, `POSIXct`, `POSIXlt`
15 | #' or anything else that can be coerced to a date with `as.Date()`.
16 | #' Defaults to `'1900-01-01'`.
17 | #'
18 | #' @param end_date Only includes amendments to bills introduced on or before
19 | #' this date. Accepts character values in `'YYYY-MM-DD'` format, and
20 | #' objects of class `Date`, `POSIXt`, `POSIXct`, `POSIXlt`
21 | #' or anything else that can be coerced to a date with `as.Date()`.
22 | #' Defaults to the current system date.
23 | #' @inheritParams all_answered_questions
24 | #' @return A tibble with details on amendments proposed by the House of Lords.
25 | #'
26 | #' @export
27 | #' @examples
28 | #' \dontrun{
29 | #' x <- lords_amendments()
30 | #'
31 | #' x <- lords_amendments(decision = "Withdrawn")
32 | #' }
33 | #'
34 | lords_amendments <- function(decision = NULL, start_date = "1900-01-01",
35 | end_date = Sys.Date(), extra_args = NULL,
36 | tidy = TRUE, tidy_style = "snake",
37 | verbose = TRUE) {
38 | dates <- paste0(
39 | "&min-bill.date=", as.Date(start_date),
40 | "&max-bill.date=", as.Date(end_date)
41 | )
42 |
43 | if (!is.null(decision)) {
44 | decision_query <- paste0("&decision=", gsub(
45 | "\\b([[:lower:]])([[:lower:]]+)", "\\U\\1\\L\\2",
46 | tolower(decision),
47 | perl = TRUE
48 | ))
49 | } else {
50 | decision_query <- ""
51 | }
52 |
53 | query <- paste0(
54 | url_util, "lordsbillamendments.json?",
55 | decision_query, dates, extra_args
56 | )
57 |
58 | df <- loop_query(query, verbose) # in utils-loop.R
59 |
60 | if (nrow(df) == 0) {
61 | message("The request did not return any data.
62 | Please check your parameters.")
63 | } else {
64 | if (tidy) {
65 | df <- lords_amendments_tidy(df, tidy_style)
66 | }
67 |
68 | df
69 | }
70 | }
71 |
72 |
73 | #' @rdname lords_amendments
74 | #' @export
75 | hansard_lords_amendments <- lords_amendments
76 |
--------------------------------------------------------------------------------
/R/research_briefings_lists.R:
--------------------------------------------------------------------------------
1 |
2 | #' Lists of research briefing topics, subtopics and types.
3 | #'
4 | #' Returns lists of research briefing topics, subtopics and types.
5 | #' These functions do not accept any arguments.
6 | #'
7 | #' @rdname research_briefings_lists
8 | #' @return A list with the different research topics/subtopics/types available.
9 | #' @export
10 | #' @seealso [research_briefings()]
11 | #'
12 | #' @section Member details functions:
13 | #' \describe{
14 | #' \item{research_topics_list}{A list with the different research
15 | #' topics available}
16 | #' \item{research_subtopics_list}{A list of Parliamentary Research
17 | #' Briefings topics}
18 | #' \item{research_types_list}{A list of types of Parliamentary
19 | #' Research Briefings}
20 | #' }
21 | #' @examples
22 | #' \dontrun{
23 | #' research_topics_list <- research_topics_list()
24 | #'
25 | #' research_subtopics_list <- research_subtopics_list()
26 | #'
27 | #' research_types_list <- research_types_list()
28 | #' }
29 | #'
30 | research_topics_list <- function() {
31 | x <- jsonlite::fromJSON(paste0(url_util, "researchbriefingtopics.json?"),
32 | flatten = TRUE
33 | )
34 |
35 | research_topics_list <- as.list(x$result$items$prefLabel._value)
36 |
37 | research_topics_list
38 | }
39 |
40 |
41 | #' @rdname research_briefings_lists
42 | #' @export
43 | hansard_research_topics_list <- research_topics_list
44 |
45 |
46 |
47 | #' @rdname research_briefings_lists
48 | #' @export
49 | research_subtopics_list <- function() {
50 | x <- jsonlite::fromJSON(paste0(url_util, "researchbriefingtopics.json?"),
51 | flatten = TRUE
52 | )
53 |
54 | research_topics_list <- as.list(x$result$items$prefLabel._value)
55 |
56 | research_subtopics_list <- list()
57 |
58 | for (i in research_topics_list) {
59 | i <- utils::URLencode(i)
60 |
61 | g <- jsonlite::fromJSON(paste0(
62 | url_util, "researchbriefingsubtopics/",
63 | i, ".json?"
64 | ), flatten = TRUE)
65 |
66 | i <- utils::URLdecode(i)
67 |
68 | research_subtopics_list[[i]] <- g$result$items$prefLabel._value
69 | }
70 |
71 | research_subtopics_list
72 | }
73 |
74 | #' @rdname research_briefings_lists
75 | #' @export
76 | hansard_research_subtopics_list <- research_subtopics_list
77 |
78 |
79 | #' @rdname research_briefings_lists
80 | #' @export
81 | research_types_list <- function() {
82 | x <- jsonlite::fromJSON(paste0(url_util, "researchbriefingtypes.json?"))
83 |
84 | research_types_list <- as.list(x$result$items$prefLabel$`_value`)
85 |
86 | research_types_list
87 | }
88 |
89 |
90 | #' @rdname research_briefings_lists
91 | #' @export
92 | hansard_research_types_list <- research_types_list
93 |
--------------------------------------------------------------------------------
/R/bills.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' Bill data
4 | #'
5 | #' Imports data on House of Commons and House of Lords bills.
6 | #'
7 | #'
8 | #' @param ID The ID of a given bill to return data on. If `NULL`,
9 | #' returns all bills, subject to other parameters. Defaults to `NULL`.
10 | #'
11 | #'
12 | #' @param amendments If `TRUE`, returns all bills with amendments,
13 | #' subject to other parameters. Defaults to `FALSE`.
14 | #'
15 | #'
16 | #' @param start_date Only includes bills introduced on or after this date.
17 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
18 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
19 | #' anything else that can be coerced to a date with `as.Date()`.
20 | #' Defaults to `'1900-01-01'`.
21 | #'
22 | #'
23 | #' @param end_date Only includes bills introduced on or before this date.
24 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
25 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
26 | #' anything else that can be coerced to a date with `as.Date()`.
27 | #' Defaults to the current system date.
28 | #'
29 | #' @inheritParams all_answered_questions
30 | #'
31 | #' @return A tibble with details on bills before the House of Lords
32 | #' and the House of Commons.
33 | #'
34 | #' @seealso [bill_stage_types()]
35 | #' @seealso [bill_publications()]
36 | #' @export
37 | #'
38 | #' @examples
39 | #' \dontrun{
40 | #' # Download data on all bills
41 | #' x <- bills()
42 | #'
43 | #' # Download data on all bill amendments
44 | #' x <- bills(amendments = TRUE)
45 | #'
46 | #' # Download data on a specific bills
47 | #' x <- bills(1719)
48 | #'
49 | #' # Download data on all bills introduced after a given date
50 | #' x <- bills(start_date = "2016-01-01")
51 | #' }
52 | #'
53 | bills <- function(ID = NULL, amendments = FALSE, start_date = "1900-01-01",
54 | end_date = Sys.Date(), extra_args = NULL, tidy = TRUE,
55 | tidy_style = "snake", verbose = TRUE) {
56 | dates <- paste0(
57 | "&_properties=date&max-date=",
58 | as.Date(end_date),
59 | "&min-date=",
60 | as.Date(start_date)
61 | )
62 |
63 | id_query <- ifelse(!is.null(ID), paste0("&identifier=", ID), "")
64 |
65 | amend_query <- ifelse(amendments, "withamendments.json?", ".json?")
66 |
67 | query <- paste0(
68 | url_util, "bills", amend_query,
69 | dates, id_query, extra_args
70 | )
71 |
72 | df <- loop_query(query, verbose) # in utils-loop.R
73 |
74 | if (nrow(df) == 0) {
75 | message("The request did not return any data.
76 | Please check your parameters.")
77 | } else {
78 | if (tidy) {
79 | df <- bills_tidy(df, tidy_style) ### in utils-bills.R
80 | }
81 | df
82 | }
83 | }
84 |
85 |
86 | #' @rdname bills
87 | #' @export
88 | hansard_bills <- bills
89 |
--------------------------------------------------------------------------------
/man/commons_oral_question_times.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/commons_oral_question_times.R
3 | \name{commons_oral_question_times}
4 | \alias{commons_oral_question_times}
5 | \alias{hansard_commons_oral_question_times}
6 | \title{Commons oral question times}
7 | \usage{
8 | commons_oral_question_times(
9 | session = NULL,
10 | question_id = NULL,
11 | extra_args = NULL,
12 | tidy = TRUE,
13 | tidy_style = "snake",
14 | verbose = TRUE
15 | )
16 |
17 | hansard_commons_oral_question_times(
18 | session = NULL,
19 | question_id = NULL,
20 | extra_args = NULL,
21 | tidy = TRUE,
22 | tidy_style = "snake",
23 | verbose = TRUE
24 | )
25 | }
26 | \arguments{
27 | \item{session}{Accepts a session in format \code{yyyy/yy}
28 | (e.g. \code{"2016/17"}) and returns a tibble of all oral question times from
29 | that session. Defaults to \code{NULL}.}
30 |
31 | \item{question_id}{Accepts a question time ID, and returns a tibble of
32 | that question time.}
33 |
34 | \item{extra_args}{Additional parameters and queries to pass to API. These
35 | queries must be strings and start with "&". See the
36 | \href{http://explore.data.parliament.uk/}{API documentation}
37 | or the package vignette for more details. Defaults to \code{NULL}.}
38 |
39 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
40 | in the tibble to remove special characters and superfluous text, and
41 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
42 |
43 | \item{tidy_style}{The style to convert variable names to, if
44 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
45 | Defaults to \code{'snake'}.}
46 |
47 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
48 | progress of the API request. Defaults to \code{TRUE}.}
49 | }
50 | \value{
51 | A tibble with information on oral question times in the House of
52 | Commons.
53 | }
54 | \description{
55 | Imports data on House of Commons oral question times. Query with parameters
56 | for the parliamentary session or the question ID. If \code{tidy=TRUE},
57 | datetime variables are converted to \code{POSIXct} class.
58 | }
59 | \examples{
60 | \dontrun{
61 | x <- commons_oral_question_times(session = "2016/17", question_id = "685697")
62 | }
63 |
64 | }
65 | \seealso{
66 | \code{\link[=all_answered_questions]{all_answered_questions()}}
67 |
68 | \code{\link[=commons_answered_questions]{commons_answered_questions()}}
69 |
70 | \code{\link[=commons_oral_questions]{commons_oral_questions()}}
71 |
72 | \code{\link[=commons_written_questions]{commons_written_questions()}}
73 |
74 | \code{\link[=lords_written_questions]{lords_written_questions()}}
75 |
76 | \code{\link[=mp_questions]{mp_questions()}}
77 | }
78 |
--------------------------------------------------------------------------------
/docs/jquery.sticky-kit.min.js:
--------------------------------------------------------------------------------
1 | /* Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | */
2 | /*
3 | Source: https://github.com/leafo/sticky-kit
4 | License: MIT
5 | */
6 | (function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k));
7 | if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b(""))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q,
8 | u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}),
10 | a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize",
11 | y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n= as.Date(start_date), ]
60 | }
61 |
62 | if (nrow(df) == 0) {
63 | message("The request did not return any data.
64 | Please check your parameters.")
65 | } else {
66 | if (tidy) {
67 | df <- sessions_tidy(df, days, tidy_style) ## in utils-sessions.R
68 | }
69 |
70 | df
71 | }
72 | }
73 |
74 |
75 | #' @rdname sessions_info
76 | #' @export
77 | hansard_sessions_info <- sessions_info
78 |
--------------------------------------------------------------------------------
/R/lords_attendance_session.R:
--------------------------------------------------------------------------------
1 |
2 | #' House of Lords attendance by session
3 | #'
4 | #' Imports data on House of Lords attendance from each parliamentary session.
5 | #' Please note that the attendance data is not as tidy as some of the others
6 | #' that are accessible through this API, and so additional work to prepare
7 | #' this data in a way that you want may be required.
8 | #'
9 | #' To return a tibble with all codes from available individual sessions, use
10 | #' `lords_attendance_session(session_id=NULL)`, or use
11 | #' [lords_sessions()] to retrieve codes for a given date range.
12 | #' Attendance from multiple sessions can be accessed by using `lapply`
13 | #' with the output from [lords_sessions()].
14 | #'
15 | #' Please note that House of Lords attendance data is not as tidy as some of
16 | #' the others that are accessible through this API, and so additional work
17 | #' on the return from the API may be required.
18 | #'
19 | #' Also note that this API does not appear to have been
20 | #' updated with data after 2017-01-31.
21 | #'
22 | #' @param session_id The ID of the House of Lords session. If `NULL`,
23 | #' returns a list of all sessions, subject to other parameters.
24 | #' Defaults to `NULL`.
25 | #' @inheritParams all_answered_questions
26 | #' @return A tibble with details on the lords who attended a given session.
27 | #' @export
28 | #' @seealso [lords_attendance_date()]
29 | #' @seealso [lords_sessions()]
30 | #'
31 | #' @examples
32 | #' \dontrun{
33 | #' x <- lords_attendance_session(session_id = 706178)
34 | #'
35 | #' # Returns a list of data frames with details of
36 | #' # attendance for each day of a given vector of sessions.
37 | #' u <- lords_sessions(start_date = "2017-01-01")
38 | #' m <- lapply(u$about, lords_attendance_session)
39 | #' }
40 | #'
41 | lords_attendance_session <- function(session_id = NULL, extra_args = NULL,
42 | tidy = TRUE, tidy_style = "snake",
43 | verbose = TRUE) {
44 | if (!is.null(session_id)) {
45 | json_query <- paste0("/", session_id, ".json?")
46 | } else {
47 | json_query <- ".json?"
48 | }
49 |
50 | query <- paste0(url_util, "lordsattendances", json_query, extra_args)
51 |
52 | attend <- jsonlite::fromJSON(query, flatten = TRUE)
53 |
54 | if (!is.null(session_id)) {
55 | veb(verbose)
56 | df <- tibble::as_tibble(as.data.frame(attend$result$primaryTopic))
57 | } else {
58 | df <- loop_query(query, verbose) # in utils-loop.R
59 | }
60 |
61 | if (nrow(df) == 0) {
62 | message("The request did not return any data.
63 | Please check your parameters.")
64 | } else {
65 | if (tidy) {
66 | df <- lords_attendance_tidy(df, tidy_style)
67 | }
68 |
69 | df
70 | }
71 | }
72 |
73 |
74 |
75 | #' @rdname lords_attendance_session
76 | #' @export
77 | hansard_lords_attendance_session <- lords_attendance_session
78 |
--------------------------------------------------------------------------------
/man/papers_laid.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/papers_laid.R
3 | \name{papers_laid}
4 | \alias{papers_laid}
5 | \alias{hansard_papers_laid}
6 | \title{Papers laid}
7 | \usage{
8 | papers_laid(
9 | withdrawn = FALSE,
10 | house = NULL,
11 | start_date = "1900-01-01",
12 | end_date = Sys.Date(),
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = TRUE
17 | )
18 |
19 | hansard_papers_laid(
20 | withdrawn = FALSE,
21 | house = NULL,
22 | start_date = "1900-01-01",
23 | end_date = Sys.Date(),
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = TRUE
28 | )
29 | }
30 | \arguments{
31 | \item{withdrawn}{If \code{TRUE}, only returns withdrawn papers.
32 | Defaults to \code{FALSE}.}
33 |
34 | \item{house}{The house the paper was laid in. Accepts \code{'commons'}
35 | and \code{'lords'}. If \code{NULL}, returns both House of Commons and
36 | House of Lords. This parameter is case-insensitive. Defaults to \code{NULL}.}
37 |
38 | \item{start_date}{Only includes papers laid before the House on or after
39 | this date. Accepts character values in \code{'YYYY-MM-DD'} format, and
40 | objects of class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt}
41 | or anything else that can be coerced to a date with \code{as.Date()}.
42 | Defaults to \code{'1900-01-01'}.}
43 |
44 | \item{end_date}{Only includes papers laid before the House on or before
45 | this date. Accepts character values in \code{'YYYY-MM-DD'} format, and
46 | objects of class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt}
47 | or anything else that can be coerced to a date with \code{as.Date()}.
48 | Defaults to the current system date.}
49 |
50 | \item{extra_args}{Additional parameters and queries to pass to API. These
51 | queries must be strings and start with "&". See the
52 | \href{http://explore.data.parliament.uk/}{API documentation}
53 | or the package vignette for more details. Defaults to \code{NULL}.}
54 |
55 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
56 | in the tibble to remove special characters and superfluous text, and
57 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
58 |
59 | \item{tidy_style}{The style to convert variable names to, if
60 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
61 | Defaults to \code{'snake'}.}
62 |
63 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
64 | progress of the API request. Defaults to \code{TRUE}.}
65 | }
66 | \value{
67 | A tibble with details on papers laid before the given House.
68 | }
69 | \description{
70 | Imports data on papers laid before the House.
71 | }
72 | \examples{
73 | \dontrun{
74 | x <- papers_laid(withdrawn = FALSE, house = "commons")
75 |
76 | x <- papers_laid(withdrawn = TRUE, house = NULL)
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/R/epetition.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' Individual epetitions
4 | #'
5 | #' Imports data on a given epetition. For bulk epetion data,
6 | #' see [epetition_tibble()].
7 | #'
8 | #' @param ID The ID of a given petition. If `NULL`, returns all
9 | #' epetitions. Defaults to `NULL`. See [epetition_tibble()]
10 | #' for a greater degree of flexibility when querying all epetitions.
11 | #'
12 | #' @param by_constituency Accepts either `TRUE` or `FALSE`.
13 | #' If `TRUE`, provides a tibble with a breakdown of signatures for
14 | #' each petition, by constituency. Defaults to `FALSE`.
15 | #' @inheritParams all_answered_questions
16 | #' @return A tibble with details on electronic petitions
17 | #' submitted to parliament.
18 | #' @seealso [epetition_tibble()]
19 | #'
20 | #' @export
21 | #' @examples
22 | #' \dontrun{
23 | #' x <- epetition(ID = 706964, by_constituency = TRUE)
24 | #' }
25 | #'
26 | epetition <- function(ID = NULL, by_constituency = FALSE,
27 | extra_args = NULL, tidy = TRUE,
28 | tidy_style = "snake", verbose = TRUE) {
29 | if (!is.null(ID)) {
30 | ID <- paste0("/", ID)
31 | }
32 |
33 | if (by_constituency) {
34 | json_query <- "/signaturesbyconstituency.json?"
35 | } else {
36 | json_query <- ".json?"
37 | }
38 |
39 | baseurl <- paste0(url_util, "epetitions")
40 |
41 | if (!is.null(ID) & !by_constituency) {
42 | veb(verbose)
43 |
44 | petition <- jsonlite::fromJSON(paste0(
45 | baseurl, ID,
46 | json_query, extra_args
47 | ),
48 | flatten = TRUE
49 | )
50 |
51 | df <- tibble::tibble(
52 | about = petition$result$primaryTopic$`_about`,
53 | abstract = petition$result$primaryTopic$abstract$`_value`,
54 | created = petition$result$primaryTopic$created$`_value`,
55 | identifier = petition$result$primaryTopic$identifier$`_value`,
56 | isPrimaryTopicOf = petition$result$primaryTopic$isPrimaryTopicOf,
57 | label = petition$result$primaryTopic$label$`_value`,
58 | modified = petition$result$primaryTopic$modified$`_value`,
59 | numberOfSignatures = petition$result$primaryTopic$numberOfSignatures,
60 | replyActionAbout = petition$result$primaryTopic$replyAction$`_about`,
61 | replyAction =
62 | petition$result$primaryTopic$replyAction$abstract$`_value`,
63 | status = petition$result$primaryTopic$status,
64 | subType = petition$result$primaryTopic$subType$`_about`,
65 | website = petition$result$primaryTopic$website
66 | )
67 | } else {
68 | query <- paste0(baseurl, ID, json_query, extra_args)
69 |
70 | df <- loop_query(query, verbose) # in utils-loop.R
71 |
72 | df$member <- NULL # Removes superfluous member column
73 | }
74 |
75 | if (nrow(df) == 0) {
76 | message("The request did not return any data.
77 | Please check your parameters.")
78 | } else {
79 | if (tidy) {
80 | df <- hansard_tidy(df, tidy_style)
81 | }
82 |
83 | df
84 | }
85 | }
86 |
87 |
88 | #' @rdname epetition
89 | #' @export
90 | hansard_epetition <- epetition
91 |
--------------------------------------------------------------------------------
/R/bill_publications.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' Bill Publications
4 | #'
5 | #' Returns details of all publications associated with a specific bill
6 | #' or all bills.
7 | #'
8 | #'
9 | #' @param ID The ID of a specific bill to return publications for.
10 | #' If `NULL`, returns all bill publications subject to other parameters.
11 | #' Defaults to `NULL`.
12 | #'
13 | #'
14 | #' @param publication_type The type of bill publication to return, in the form
15 | #' of a string. For a character vector of bill publication types, see
16 | #' [bill_publication_types()]. If `NULL`, returns all
17 | #' publications of all types, subject to other parameters.
18 | #' Defaults to `NULL`.
19 | #'
20 | #'
21 | #' @param start_date Only includes bill publications on or after this date.
22 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
23 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
24 | #' anything else that can be coerced to a date with `as.Date()`.
25 | #' Defaults to `'1900-01-01'`.
26 | #'
27 | #'
28 | #' @param end_date Only includes bill publicationson or before this date.
29 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
30 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
31 | #' anything else that can be coerced to a date with `as.Date()`.
32 | #' Defaults to the current system date.
33 | #'
34 | #' @inheritParams all_answered_questions
35 | #'
36 | #' @return A tibble with details on bill publications.
37 | #' @export
38 | #' @seealso [bill_stage_types()]
39 | #' @seealso [bills()]
40 | #' @seealso [bill_publication_types()]
41 | #'
42 | #' @examples
43 | #' \dontrun{
44 | #' # Requesting a specific publication
45 | #' x <- bill_publications(ID = 752025)
46 | #'
47 | #' # Requesting all publications after a given date
48 | #' y <- bill_publications(start_date = "2018-01-01")
49 | #' }
50 | bill_publications <- function(ID = NULL, publication_type = NULL,
51 | start_date = "1900-01-01", end_date = Sys.Date(),
52 | extra_args = NULL, tidy = TRUE,
53 | tidy_style = "snake", verbose = FALSE) {
54 | dates <- paste0(
55 | "&max-date=",
56 | as.Date(end_date),
57 | "&min-date=",
58 | as.Date(start_date)
59 | )
60 |
61 | bill_id <- ifelse(is.null(ID),
62 | "",
63 | paste0("&bill=http://data.parliament.uk/resources/", ID)
64 | )
65 |
66 | if (is.null(publication_type)) {
67 | pub_query <- ""
68 | } else {
69 | pub_query <- utils::URLencode(paste0(
70 | "&publicationType=",
71 | publication_type
72 | ))
73 | }
74 |
75 | query <- paste0(
76 | url_util, "billpublications.json?", bill_id, dates, extra_args
77 | )
78 |
79 | df <- loop_query(query, verbose) # in utils-loop.R
80 |
81 | if (nrow(df) == 0) {
82 | message("The request did not return any data.
83 | Please check your parameters.")
84 | } else {
85 | if (tidy) {
86 | df <- bills_tidy(df, tidy_style) # in utils-bills.R
87 | }
88 |
89 | df
90 | }
91 | }
92 |
93 | #' @rdname bill_publications
94 | #' @export
95 | hansard_bill_publications <- bill_publications
96 |
--------------------------------------------------------------------------------
/man/publication_logs.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/publication_logs.R
3 | \name{publication_logs}
4 | \alias{publication_logs}
5 | \alias{hansard_publication_logs}
6 | \title{House publications}
7 | \usage{
8 | publication_logs(
9 | ID = NULL,
10 | house = NULL,
11 | start_date = "1900-01-01",
12 | end_date = Sys.Date(),
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = TRUE
17 | )
18 |
19 | hansard_publication_logs(
20 | ID = NULL,
21 | house = NULL,
22 | start_date = "1900-01-01",
23 | end_date = Sys.Date(),
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = TRUE
28 | )
29 | }
30 | \arguments{
31 | \item{ID}{Publication ID. Defaults to \code{NULL}. If not \code{NULL},
32 | requests a tibble with information on the given publication.}
33 |
34 | \item{house}{The house that produced the particular publication. Accepts
35 | \code{'commons'} and \code{'lords'}. If \code{NULL} or not \code{'commons'}
36 | or \code{'lords'}, returns publications from both House of Commons and
37 | House of Lords. This parameter is case-insensitive. Defaults to \code{NULL}.}
38 |
39 | \item{start_date}{Only includes publications issued on or after this date.
40 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
41 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
42 | anything else that can be coerced to a date with \code{as.Date()}.
43 | Defaults to \code{'1900-01-01'}.}
44 |
45 | \item{end_date}{Only includes publications issued on or before this
46 | date. Accepts character values in \code{'YYYY-MM-DD'} format, and
47 | objects of class \code{Date}, \code{POSIXt}, \code{POSIXct},
48 | \code{POSIXlt} or anything else that can be coerced to a date with
49 | \code{as.Date()}. Defaults to the current system date.}
50 |
51 | \item{extra_args}{Additional parameters and queries to pass to API. These
52 | queries must be strings and start with "&". See the
53 | \href{http://explore.data.parliament.uk/}{API documentation}
54 | or the package vignette for more details. Defaults to \code{NULL}.}
55 |
56 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
57 | in the tibble to remove special characters and superfluous text, and
58 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
59 |
60 | \item{tidy_style}{The style to convert variable names to, if
61 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
62 | Defaults to \code{'snake'}.}
63 |
64 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
65 | progress of the API request. Defaults to \code{TRUE}.}
66 | }
67 | \value{
68 | A tibble with details from publications in the House of
69 | Commons and House of Lords
70 | }
71 | \description{
72 | Imports data on House of Commons and House of Lords publications.
73 | }
74 | \examples{
75 | \dontrun{
76 | # All publications in the house of commons
77 | x <- publication_logs(house = "commons")
78 |
79 | # Returns a given publication
80 | y <- publication_logs(683267)
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/R/papers_laid.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' Papers laid
4 | #'
5 | #' Imports data on papers laid before the House.
6 | #'
7 | #' @param withdrawn If `TRUE`, only returns withdrawn papers.
8 | #' Defaults to `FALSE`.
9 | #'
10 | #' @param house The house the paper was laid in. Accepts `'commons'`
11 | #' and `'lords'`. If `NULL`, returns both House of Commons and
12 | #' House of Lords. This parameter is case-insensitive. Defaults to `NULL`.
13 | #'
14 | #' @param start_date Only includes papers laid before the House on or after
15 | #' this date. Accepts character values in `'YYYY-MM-DD'` format, and
16 | #' objects of class `Date`, `POSIXt`, `POSIXct`, `POSIXlt`
17 | #' or anything else that can be coerced to a date with `as.Date()`.
18 | #' Defaults to `'1900-01-01'`.
19 | #'
20 | #' @param end_date Only includes papers laid before the House on or before
21 | #' this date. Accepts character values in `'YYYY-MM-DD'` format, and
22 | #' objects of class `Date`, `POSIXt`, `POSIXct`, `POSIXlt`
23 | #' or anything else that can be coerced to a date with `as.Date()`.
24 | #' Defaults to the current system date.
25 | #' @inheritParams all_answered_questions
26 | #' @return A tibble with details on papers laid before the given House.
27 | #' @export
28 | #' @examples
29 | #' \dontrun{
30 | #' x <- papers_laid(withdrawn = FALSE, house = "commons")
31 | #'
32 | #' x <- papers_laid(withdrawn = TRUE, house = NULL)
33 | #' }
34 | #'
35 | papers_laid <- function(withdrawn = FALSE, house = NULL,
36 | start_date = "1900-01-01", end_date = Sys.Date(),
37 | extra_args = NULL, tidy = TRUE,
38 | tidy_style = "snake", verbose = TRUE) {
39 | house <- tolower(house)
40 |
41 | house_query <- house_query_util(house) ## in utils-house.R
42 |
43 | with_q <- ifelse(
44 | withdrawn == TRUE,
45 | "&withdrawn=true",
46 | "&withdrawn=false"
47 | )
48 |
49 | dates <- paste0(
50 | "&max-ddpModified=", as.Date(end_date),
51 | "&min-ddpModified=", as.Date(start_date)
52 | )
53 |
54 | query <- paste0(
55 | url_util, "paperslaid.json?", with_q, house_query, dates, extra_args
56 | )
57 |
58 | df <- loop_query(query, verbose) # in utils-loop.R
59 |
60 | if (nrow(df) == 0) {
61 | message("The request did not return any data.
62 | Please check your parameters.")
63 | } else {
64 | if (tidy) { ### move this to external utils file?
65 |
66 | df$dateLaid._value <- as.POSIXct(df$dateLaid._value)
67 |
68 | df$dateLaid._datatype <- "POSIXct"
69 |
70 | if (withdrawn) {
71 | df$dateWithdrawn._value <- gsub(
72 | "T", " ",
73 | df$dateWithdrawn._value
74 | )
75 |
76 | df$dateWithdrawn._value <- as.POSIXct(
77 | lubridate::parse_date_time(
78 | df$dateWithdrawn._value,
79 | "Y-m-d H:M:S"
80 | )
81 | )
82 |
83 | df$dateWithdrawn._datatype <- "POSIXct"
84 | }
85 |
86 | df <- hansard_tidy(df, tidy_style)
87 | }
88 |
89 | df
90 | }
91 | }
92 |
93 |
94 | #' @rdname papers_laid
95 | #' @export
96 | hansard_papers_laid <- papers_laid
97 |
--------------------------------------------------------------------------------
/R/publication_logs.R:
--------------------------------------------------------------------------------
1 |
2 | #' House publications
3 | #'
4 | #' Imports data on House of Commons and House of Lords publications.
5 | #'
6 | #' @param ID Publication ID. Defaults to `NULL`. If not `NULL`,
7 | #' requests a tibble with information on the given publication.
8 | #'
9 | #' @param house The house that produced the particular publication. Accepts
10 | #' `'commons'` and `'lords'`. If `NULL` or not `'commons'`
11 | #' or `'lords'`, returns publications from both House of Commons and
12 | #' House of Lords. This parameter is case-insensitive. Defaults to `NULL`.
13 | #'
14 | #' @param start_date Only includes publications issued on or after this date.
15 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
16 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
17 | #' anything else that can be coerced to a date with `as.Date()`.
18 | #' Defaults to `'1900-01-01'`.
19 | #'
20 | #' @param end_date Only includes publications issued on or before this
21 | #' date. Accepts character values in `'YYYY-MM-DD'` format, and
22 | #' objects of class `Date`, `POSIXt`, `POSIXct`,
23 | #' `POSIXlt` or anything else that can be coerced to a date with
24 | #' `as.Date()`. Defaults to the current system date.
25 | #' @inheritParams all_answered_questions
26 | #' @return A tibble with details from publications in the House of
27 | #' Commons and House of Lords
28 | #' @export
29 | #' @examples
30 | #' \dontrun{
31 | #' # All publications in the house of commons
32 | #' x <- publication_logs(house = "commons")
33 | #'
34 | #' # Returns a given publication
35 | #' y <- publication_logs(683267)
36 | #' }
37 | #'
38 | publication_logs <- function(ID = NULL, house = NULL, start_date = "1900-01-01",
39 | end_date = Sys.Date(), extra_args = NULL,
40 | tidy = TRUE, tidy_style = "snake",
41 | verbose = TRUE) {
42 | id_query <- ifelse(
43 | is.null(ID) == FALSE,
44 | paste0("/", ID, ".json?"),
45 | ".json?"
46 | )
47 |
48 | if (is.null(house)) {
49 | house_query <- ""
50 | } else {
51 | house <- tolower(house)
52 |
53 | house_query <- house_query_util(house) ## in utils-house.R
54 | }
55 |
56 | dates <- paste0(
57 | "&_properties=publicationDate&max-publicationDate=",
58 | as.Date(end_date),
59 | "&min-publicationDate=",
60 | as.Date(start_date)
61 | )
62 |
63 | veb(verbose)
64 |
65 | query <- paste0(url_util, "publicationlogs", id_query, house_query, dates, extra_args)
66 |
67 | logs <- jsonlite::fromJSON(query, flatten = TRUE)
68 |
69 | if (is.null(ID) == FALSE) {
70 | df <- tibble::as_tibble(as.data.frame(logs$result$primaryTopic))
71 | } else {
72 | df <- loop_query(query, verbose) # in utils-loop.R
73 | }
74 |
75 | if (nrow(df) == 0) {
76 | message("The request did not return any data.
77 | Please check your parameters.")
78 | } else {
79 | if (tidy) {
80 | df <- pub_tidy(df, tidy_style) ## in utils-publogs.R
81 | }
82 |
83 | df
84 | }
85 | }
86 |
87 |
88 | #' @rdname publication_logs
89 | #' @export
90 | hansard_publication_logs <- publication_logs
91 |
--------------------------------------------------------------------------------
/man/bills.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/bills.R
3 | \name{bills}
4 | \alias{bills}
5 | \alias{hansard_bills}
6 | \title{Bill data}
7 | \usage{
8 | bills(
9 | ID = NULL,
10 | amendments = FALSE,
11 | start_date = "1900-01-01",
12 | end_date = Sys.Date(),
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = TRUE
17 | )
18 |
19 | hansard_bills(
20 | ID = NULL,
21 | amendments = FALSE,
22 | start_date = "1900-01-01",
23 | end_date = Sys.Date(),
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = TRUE
28 | )
29 | }
30 | \arguments{
31 | \item{ID}{The ID of a given bill to return data on. If \code{NULL},
32 | returns all bills, subject to other parameters. Defaults to \code{NULL}.}
33 |
34 | \item{amendments}{If \code{TRUE}, returns all bills with amendments,
35 | subject to other parameters. Defaults to \code{FALSE}.}
36 |
37 | \item{start_date}{Only includes bills introduced on or after this date.
38 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
39 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
40 | anything else that can be coerced to a date with \code{as.Date()}.
41 | Defaults to \code{'1900-01-01'}.}
42 |
43 | \item{end_date}{Only includes bills introduced on or before this date.
44 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
45 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
46 | anything else that can be coerced to a date with \code{as.Date()}.
47 | Defaults to the current system date.}
48 |
49 | \item{extra_args}{Additional parameters and queries to pass to API. These
50 | queries must be strings and start with "&". See the
51 | \href{http://explore.data.parliament.uk/}{API documentation}
52 | or the package vignette for more details. Defaults to \code{NULL}.}
53 |
54 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
55 | in the tibble to remove special characters and superfluous text, and
56 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
57 |
58 | \item{tidy_style}{The style to convert variable names to, if
59 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
60 | Defaults to \code{'snake'}.}
61 |
62 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
63 | progress of the API request. Defaults to \code{TRUE}.}
64 | }
65 | \value{
66 | A tibble with details on bills before the House of Lords
67 | and the House of Commons.
68 | }
69 | \description{
70 | Imports data on House of Commons and House of Lords bills.
71 | }
72 | \examples{
73 | \dontrun{
74 | # Download data on all bills
75 | x <- bills()
76 |
77 | # Download data on all bill amendments
78 | x <- bills(amendments = TRUE)
79 |
80 | # Download data on a specific bills
81 | x <- bills(1719)
82 |
83 | # Download data on all bills introduced after a given date
84 | x <- bills(start_date = "2016-01-01")
85 | }
86 |
87 | }
88 | \seealso{
89 | \code{\link[=bill_stage_types]{bill_stage_types()}}
90 |
91 | \code{\link[=bill_publications]{bill_publications()}}
92 | }
93 |
--------------------------------------------------------------------------------
/man/sessions_info.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/sessions_info.R
3 | \name{sessions_info}
4 | \alias{sessions_info}
5 | \alias{hansard_sessions_info}
6 | \title{Parliamentary Session data}
7 | \usage{
8 | sessions_info(
9 | days = FALSE,
10 | start_date = "1900-01-01",
11 | end_date = Sys.Date(),
12 | extra_args = NULL,
13 | tidy = TRUE,
14 | tidy_style = "snake",
15 | verbose = TRUE
16 | )
17 |
18 | hansard_sessions_info(
19 | days = FALSE,
20 | start_date = "1900-01-01",
21 | end_date = Sys.Date(),
22 | extra_args = NULL,
23 | tidy = TRUE,
24 | tidy_style = "snake",
25 | verbose = TRUE
26 | )
27 | }
28 | \arguments{
29 | \item{days}{If \code{TRUE}, returns data for all available days. If
30 | \code{FALSE}, returns data on each parliamentary session. If \code{TRUE}
31 | and non-default \code{start_date} and/or \code{end_date} parameters are
32 | requested, the function must retrieve all days and subset based on the
33 | values passed to \code{start_date} and \code{end_date}. Not applicable
34 | to \code{lords_sessions}. Defaults to \code{FALSE}.}
35 |
36 | \item{start_date}{Only includes sessions starting on or after this date.
37 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
38 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or anything
39 | else that can be coerced to a date with \code{as.Date()}. Defaults to
40 | \code{'1900-01-01'}.}
41 |
42 | \item{end_date}{Only includes sessions ending on or before this date.
43 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
44 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
45 | anything else that can be coerced to a date with \code{as.Date()}.
46 | Defaults to the current system date.}
47 |
48 | \item{extra_args}{Additional parameters and queries to pass to API. These
49 | queries must be strings and start with "&". See the
50 | \href{http://explore.data.parliament.uk/}{API documentation}
51 | or the package vignette for more details. Defaults to \code{NULL}.}
52 |
53 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
54 | in the tibble to remove special characters and superfluous text, and
55 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
56 |
57 | \item{tidy_style}{The style to convert variable names to, if
58 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
59 | Defaults to \code{'snake'}.}
60 |
61 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
62 | progress of the API request. Defaults to \code{TRUE}.}
63 | }
64 | \value{
65 | A tibble with details on parliamentary sessions.
66 | }
67 | \description{
68 | Imports data on Parliamentary Sessions. Note that due to the date format
69 | used by the API, if \code{days==TRUE} and the \code{end_date} and
70 | \code{start_date} parameters are not set to the default values, the
71 | function downloads all available data and then subsets the tibble
72 | between the two given dates.
73 | }
74 | \examples{
75 | \dontrun{
76 | x <- sessions_info(days = TRUE)
77 |
78 | y <- sessions_info(days = FALSE)
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/man/lords_attendance_session.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/lords_attendance_session.R
3 | \name{lords_attendance_session}
4 | \alias{lords_attendance_session}
5 | \alias{hansard_lords_attendance_session}
6 | \title{House of Lords attendance by session}
7 | \usage{
8 | lords_attendance_session(
9 | session_id = NULL,
10 | extra_args = NULL,
11 | tidy = TRUE,
12 | tidy_style = "snake",
13 | verbose = TRUE
14 | )
15 |
16 | hansard_lords_attendance_session(
17 | session_id = NULL,
18 | extra_args = NULL,
19 | tidy = TRUE,
20 | tidy_style = "snake",
21 | verbose = TRUE
22 | )
23 | }
24 | \arguments{
25 | \item{session_id}{The ID of the House of Lords session. If \code{NULL},
26 | returns a list of all sessions, subject to other parameters.
27 | Defaults to \code{NULL}.}
28 |
29 | \item{extra_args}{Additional parameters and queries to pass to API. These
30 | queries must be strings and start with "&". See the
31 | \href{http://explore.data.parliament.uk/}{API documentation}
32 | or the package vignette for more details. Defaults to \code{NULL}.}
33 |
34 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
35 | in the tibble to remove special characters and superfluous text, and
36 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
37 |
38 | \item{tidy_style}{The style to convert variable names to, if
39 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
40 | Defaults to \code{'snake'}.}
41 |
42 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
43 | progress of the API request. Defaults to \code{TRUE}.}
44 | }
45 | \value{
46 | A tibble with details on the lords who attended a given session.
47 | }
48 | \description{
49 | Imports data on House of Lords attendance from each parliamentary session.
50 | Please note that the attendance data is not as tidy as some of the others
51 | that are accessible through this API, and so additional work to prepare
52 | this data in a way that you want may be required.
53 | }
54 | \details{
55 | To return a tibble with all codes from available individual sessions, use
56 | \code{lords_attendance_session(session_id=NULL)}, or use
57 | \code{\link[=lords_sessions]{lords_sessions()}} to retrieve codes for a given date range.
58 | Attendance from multiple sessions can be accessed by using \code{lapply}
59 | with the output from \code{\link[=lords_sessions]{lords_sessions()}}.
60 |
61 | Please note that House of Lords attendance data is not as tidy as some of
62 | the others that are accessible through this API, and so additional work
63 | on the return from the API may be required.
64 |
65 | Also note that this API does not appear to have been
66 | updated with data after 2017-01-31.
67 | }
68 | \examples{
69 | \dontrun{
70 | x <- lords_attendance_session(session_id = 706178)
71 |
72 | # Returns a list of data frames with details of
73 | # attendance for each day of a given vector of sessions.
74 | u <- lords_sessions(start_date = "2017-01-01")
75 | m <- lapply(u$about, lords_attendance_session)
76 | }
77 |
78 | }
79 | \seealso{
80 | \code{\link[=lords_attendance_date]{lords_attendance_date()}}
81 |
82 | \code{\link[=lords_sessions]{lords_sessions()}}
83 | }
84 |
--------------------------------------------------------------------------------
/man/members.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/members.R
3 | \name{members}
4 | \alias{members}
5 | \alias{hansard_members}
6 | \alias{commons_members}
7 | \alias{hansard_commons_members}
8 | \alias{lords_members}
9 | \alias{hansard_lords_members}
10 | \title{Members of both houses}
11 | \usage{
12 | members(
13 | ID = NULL,
14 | extra_args = NULL,
15 | tidy = TRUE,
16 | tidy_style = "snake",
17 | verbose = TRUE
18 | )
19 |
20 | hansard_members(
21 | ID = NULL,
22 | extra_args = NULL,
23 | tidy = TRUE,
24 | tidy_style = "snake",
25 | verbose = TRUE
26 | )
27 |
28 | commons_members(
29 | extra_args = NULL,
30 | tidy = TRUE,
31 | tidy_style = "snake",
32 | verbose = TRUE
33 | )
34 |
35 | hansard_commons_members(
36 | extra_args = NULL,
37 | tidy = TRUE,
38 | tidy_style = "snake",
39 | verbose = TRUE
40 | )
41 |
42 | lords_members(
43 | extra_args = NULL,
44 | tidy = TRUE,
45 | tidy_style = "snake",
46 | verbose = TRUE
47 | )
48 |
49 | hansard_lords_members(
50 | extra_args = NULL,
51 | tidy = TRUE,
52 | tidy_style = "snake",
53 | verbose = TRUE
54 | )
55 | }
56 | \arguments{
57 | \item{ID}{The ID of a member of the House of Commons or the House of Lords
58 | to return data on. If \code{NULL}, returns a tibble of all members of both
59 | houses. Defaults to \code{NULL}.}
60 |
61 | \item{extra_args}{Additional parameters and queries to pass to API. These
62 | queries must be strings and start with "&". See the
63 | \href{http://explore.data.parliament.uk/}{API documentation}
64 | or the package vignette for more details. Defaults to \code{NULL}.}
65 |
66 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
67 | in the tibble to remove special characters and superfluous text, and
68 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
69 |
70 | \item{tidy_style}{The style to convert variable names to, if
71 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
72 | Defaults to \code{'snake'}.}
73 |
74 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
75 | progress of the API request. Defaults to \code{TRUE}.}
76 | }
77 | \value{
78 | A tibble with data on members of the House of Commons
79 | (\code{commons_members()}), the House of Lords, (\code{lords_members()}),
80 | or both (\code{members()}).
81 | }
82 | \description{
83 | Imports basic details on current and former Members of Parliament including
84 | the Lords and the Commons. For more details on a given member see
85 | \link[mnis]{mnis_full_biog} from the \link[mnis]{mnis} package.
86 | }
87 | \section{Member details functions}{
88 |
89 | \describe{
90 | \item{\code{members}}{Basic details on a given member from either house}
91 | \item{\code{commons_members}}{MPs in the House of Commons}
92 | \item{\code{lords_members}}{Peers in the House of Lords}
93 | }
94 | }
95 |
96 | \examples{
97 | \dontrun{
98 | a <- members()
99 |
100 | x <- members(172)
101 |
102 | y <- commons_members()
103 |
104 | z <- lords_members()
105 | }
106 |
107 | }
108 | \seealso{
109 | \code{\link[=members_search]{members_search()}}
110 | }
111 |
--------------------------------------------------------------------------------
/man/mp_vote_record.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mp_vote_record.R
3 | \name{mp_vote_record}
4 | \alias{mp_vote_record}
5 | \alias{hansard_mp_vote_record}
6 | \title{Individual MP voting records}
7 | \usage{
8 | mp_vote_record(
9 | mp_id = NULL,
10 | lobby = "all",
11 | session = NULL,
12 | start_date = "1900-01-01",
13 | end_date = Sys.Date(),
14 | extra_args = NULL,
15 | tidy = TRUE,
16 | tidy_style = "snake",
17 | verbose = TRUE
18 | )
19 |
20 | hansard_mp_vote_record(
21 | mp_id = NULL,
22 | lobby = "all",
23 | session = NULL,
24 | start_date = "1900-01-01",
25 | end_date = Sys.Date(),
26 | extra_args = NULL,
27 | tidy = TRUE,
28 | tidy_style = "snake",
29 | verbose = TRUE
30 | )
31 | }
32 | \arguments{
33 | \item{mp_id}{The ID number of a member of the House of Commons.}
34 |
35 | \item{lobby}{Accepts one of \code{'all'}, \code{'aye'} or \code{'no'}.
36 | \code{'aye'} returns votes where the MP voted \code{'aye'}, \code{'no'}
37 | returns votes where the MP voted \code{'no'}, \code{'all'} returns all
38 | available votes by the MP. This parameter is not case sensitive.
39 | Defaults to \code{'all'}.}
40 |
41 | \item{session}{The parliamentary session to return votes from, in
42 | \code{'YYYY/YY'} format. Defaults to \code{NULL}.}
43 |
44 | \item{start_date}{Only includes divisions on or after this date. Accepts
45 | character values in \code{'YYYY-MM-DD'} format, and objects of class
46 | \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or anything
47 | else that can be coerced to a date with \code{as.Date()}. Defaults to
48 | \code{'1900-01-01'}.}
49 |
50 | \item{end_date}{Only includes divisions on or before this date. Accepts
51 | character values in \code{'YYYY-MM-DD'} format, and objects of class
52 | \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or anything
53 | else that can be coerced to a date with \code{as.Date()}. Defaults to
54 | the current system date.}
55 |
56 | \item{extra_args}{Additional parameters and queries to pass to API. These
57 | queries must be strings and start with "&". See the
58 | \href{http://explore.data.parliament.uk/}{API documentation}
59 | or the package vignette for more details. Defaults to \code{NULL}.}
60 |
61 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
62 | in the tibble to remove special characters and superfluous text, and
63 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
64 |
65 | \item{tidy_style}{The style to convert variable names to, if
66 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
67 | Defaults to \code{'snake'}.}
68 |
69 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
70 | progress of the API request. Defaults to \code{TRUE}.}
71 | }
72 | \value{
73 | A tibble with details on the voting record of the given MP.
74 | }
75 | \description{
76 | Accepts an ID number for a member of the House of Commons, and returns a
77 | tibble of their votes.
78 | }
79 | \examples{
80 | \dontrun{
81 | x <- mp_vote_record(172, lobby = "all")
82 |
83 | x <- mp_vote_record(172, lobby = "aye")
84 |
85 | x <- mp_vote_record(172, lobby = "no")
86 |
87 | x <- mp_vote_record(172, session = "2016/17")
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/R/epetition_tibble.R:
--------------------------------------------------------------------------------
1 |
2 | #' Bulk Epetition data
3 | #'
4 | #' Get data on all epetitions submitted to parliament, with the label, sponsor,
5 | #' number of signatures, date created and epetition ID. For greater detail on
6 | #' indidivual epetitions, see [epetition()].
7 | #'
8 | #'
9 | #' @param min_signatures The minimum number of signatures required for
10 | #' inclusion in the tibble. Defaults to 1.
11 | #'
12 | #' @param max_signatures The maximum number of signatures required for
13 | #' inclusion in the tibble. If `NULL`, there is no maximum number of
14 | #' signatures. Defaults to `NULL`.
15 | #'
16 | #' @param status The status of the petition, either `'open'` or
17 | #' `'closed'`. If `NULL`, returns all petitions both open and
18 | #' closed. Defaults to `NULL`.
19 | #'
20 | #' @param start_date Only includes epetitions created on or after this date.
21 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
22 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
23 | #' anything else that can be coerced to a date with `as.Date()`.
24 | #' Defaults to `'1900-01-01'`.
25 | #'
26 | #' @param end_date Only includes epetitions created on or before this date.
27 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
28 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or a
29 | #' nything else that can be coerced to a date with `as.Date()`.
30 | #' Defaults to the current system date.
31 | #' @inheritParams all_answered_questions
32 | #' @return A tibble with details on electronic petitions
33 | #' submitted to parliament.
34 | #' @seealso [epetition()]
35 | #'
36 | #' @export
37 | #' @examples
38 | #' \dontrun{
39 | #' x <- epetition_tibble()
40 | #'
41 | #' y <- epetition_tibble(max_signatures = 500)
42 | #'
43 | #' z <- epetition_tibble(start_date = "2016-12-01", end_date = "2017-04-25")
44 | #' }
45 | #'
46 | epetition_tibble <- function(min_signatures = 1, max_signatures = NULL,
47 | status = NULL, start_date = "1900-01-01",
48 | end_date = Sys.Date(), extra_args = NULL,
49 | tidy = TRUE, tidy_style = "snake",
50 | verbose = TRUE) {
51 | dates <- paste0(
52 | "&max-created=", as.Date(end_date),
53 | "&min-created=", as.Date(start_date)
54 | )
55 |
56 | status_query <- ifelse(
57 | is.null(status) == TRUE,
58 | "",
59 | paste0("&status=", status)
60 | )
61 |
62 |
63 | if (is.null(max_signatures)) {
64 | sig_q <- paste0("&min-numberOfSignatures=", min_signatures)
65 | } else {
66 | sig_q <- paste0(
67 | "&min-numberOfSignatures=", min_signatures,
68 | "&max-numberOfSignatures=", max_signatures
69 | )
70 | }
71 |
72 | veb(verbose)
73 |
74 | query <- paste0(
75 | url_util, "epetitions.json?", status_query, sig_q, dates, extra_args
76 | )
77 |
78 | df <- loop_query(query, verbose) # in utils-loop.R
79 |
80 | if (nrow(df) == 0) {
81 | message("The request did not return any data.
82 | Please check your parameters.")
83 | } else {
84 | if (tidy) {
85 | df <- epetition_tibble_tidy(df, tidy_style) ## in utils-epetition.R
86 | }
87 |
88 | df
89 | }
90 | }
91 |
92 |
93 | #' @rdname epetition_tibble
94 | #' @export
95 |
96 | hansard_epetition_tibble <- epetition_tibble
97 |
--------------------------------------------------------------------------------
/man/lords_divisions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/lords_divisions.R
3 | \name{lords_divisions}
4 | \alias{lords_divisions}
5 | \alias{hansard_lords_divisions}
6 | \title{House of Lords divisions}
7 | \usage{
8 | lords_divisions(
9 | division_id = NULL,
10 | summary = FALSE,
11 | start_date = "1900-01-01",
12 | end_date = Sys.Date(),
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = TRUE
17 | )
18 |
19 | hansard_lords_divisions(
20 | division_id = NULL,
21 | summary = FALSE,
22 | start_date = "1900-01-01",
23 | end_date = Sys.Date(),
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = TRUE
28 | )
29 | }
30 | \arguments{
31 | \item{division_id}{The id of a particular vote. If empty, returns a tibble
32 | with information on all lords divisions. Defaults to \code{NULL}.}
33 |
34 | \item{summary}{If \code{TRUE}, returns a small tibble summarising a
35 | division outcome. Otherwise returns a tibble with details on how each peer
36 | voted. Has no effect if \code{division_id} is empty.
37 | Defaults to \code{FALSE}.}
38 |
39 | \item{start_date}{Only includes divisions on or after this date. Accepts
40 | character values in \code{'YYYY-MM-DD'} format, and objects of class
41 | \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or anything
42 | else that can be coerced to a date with \code{as.Date()}.
43 | Defaults to \code{'1900-01-01'}.}
44 |
45 | \item{end_date}{Only includes divisions on or before this date. Accepts
46 | character values in \code{'YYYY-MM-DD'} format, and objects of class
47 | \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or anything
48 | else that can be coerced to a date with \code{as.Date()}.
49 | Defaults to the current system date.}
50 |
51 | \item{extra_args}{Additional parameters and queries to pass to API. These
52 | queries must be strings and start with "&". See the
53 | \href{http://explore.data.parliament.uk/}{API documentation}
54 | or the package vignette for more details. Defaults to \code{NULL}.}
55 |
56 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
57 | in the tibble to remove special characters and superfluous text, and
58 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
59 |
60 | \item{tidy_style}{The style to convert variable names to, if
61 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
62 | Defaults to \code{'snake'}.}
63 |
64 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
65 | progress of the API request. Defaults to \code{TRUE}.}
66 | }
67 | \value{
68 | A tibble with the results of divisions in the House of Lords.
69 | }
70 | \description{
71 | Imports data on House of Lords divisions. Either a general query subject to
72 | parameters, or the results of a specific division. Individual divisions can
73 | be queried to return a short summary of the votes, or details on how each
74 | peer voted.
75 | }
76 | \examples{
77 | \dontrun{
78 | x <- lords_divisions(division_id = 705891, summary = TRUE)
79 |
80 | x <- lords_divisions(division_id = 705891, summary = FALSE)
81 |
82 | # Return all lords divisions in 2016
83 | x <- lords_divisions(NULL, FALSE,
84 | start_date = "2016-01-01",
85 | end_date = "2016-12-31"
86 | )
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/man/research_briefings.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/research_briefings.R
3 | \name{research_briefings}
4 | \alias{research_briefings}
5 | \alias{hansard_research_briefings}
6 | \title{Parliamentary Research Briefings}
7 | \usage{
8 | research_briefings(
9 | topic = NULL,
10 | subtopic = NULL,
11 | type = NULL,
12 | extra_args = NULL,
13 | tidy = TRUE,
14 | tidy_style = "snake",
15 | verbose = TRUE
16 | )
17 |
18 | hansard_research_briefings(
19 | topic = NULL,
20 | subtopic = NULL,
21 | type = NULL,
22 | extra_args = NULL,
23 | tidy = TRUE,
24 | tidy_style = "snake",
25 | verbose = TRUE
26 | )
27 | }
28 | \arguments{
29 | \item{topic}{The topic of the parliamentary briefing.
30 | Defaults to \code{NULL}.}
31 |
32 | \item{subtopic}{The subtopic of the parliamentary briefing.
33 | Defaults to \code{NULL}.}
34 |
35 | \item{type}{The type of research briefing. Defaults to \code{NULL}.}
36 |
37 | \item{extra_args}{Additional parameters and queries to pass to API. These
38 | queries must be strings and start with "&". See the
39 | \href{http://explore.data.parliament.uk/}{API documentation}
40 | or the package vignette for more details. Defaults to \code{NULL}.}
41 |
42 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
43 | in the tibble to remove special characters and superfluous text, and
44 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
45 |
46 | \item{tidy_style}{The style to convert variable names to, if
47 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
48 | Defaults to \code{'snake'}.}
49 |
50 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
51 | progress of the API request. Defaults to \code{TRUE}.}
52 | }
53 | \value{
54 | A tibble with details on parliamentary research briefings on
55 | the given topic.
56 | }
57 | \description{
58 | Imports data on Parliamentary Research Briefings. To see a list of possible
59 | topics call \code{\link[=research_topics_list]{research_topics_list()}} or
60 | \code{\link[=research_subtopics_list]{research_subtopics_list()}} for both topics and subtopics. To
61 | see a list of briefing types, call \code{\link[=research_types_list]{research_types_list()}}. This
62 | function can return results with newlines in the text of the abstract or
63 | description of the research briefing, represented as \code{'\\\\n'}.
64 | }
65 | \examples{
66 | \dontrun{
67 | x <- research_briefings("Housing and planning")
68 |
69 | # Requests can be made using lists created using `research_topics_list`
70 | # and `research_subtopics_list`
71 |
72 | research_topics_list <- research_topics_list()
73 |
74 | x <- research_briefings(topic = research_topics_list[[7]])
75 |
76 | research_subtopics_list <- research_subtopics_list()
77 |
78 | x <- research_briefings(subtopic = research_subtopics_list[[7]][10])
79 |
80 | # Requests for certain briefing types can also be made using lists
81 | # created with `research_types_list`.
82 |
83 | research_types_list <- research_types_list()
84 |
85 | x <- research_briefings(type = research_types_list[[3]])
86 | }
87 |
88 | }
89 | \seealso{
90 | \code{\link[=research_subtopics_list]{research_subtopics_list()}}
91 |
92 | \code{\link[=research_types_list]{research_types_list()}}
93 |
94 | \code{\link[=research_topics_list]{research_topics_list()}}
95 | }
96 |
--------------------------------------------------------------------------------
/man/bill_publications.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/bill_publications.R
3 | \name{bill_publications}
4 | \alias{bill_publications}
5 | \alias{hansard_bill_publications}
6 | \title{Bill Publications}
7 | \usage{
8 | bill_publications(
9 | ID = NULL,
10 | publication_type = NULL,
11 | start_date = "1900-01-01",
12 | end_date = Sys.Date(),
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = FALSE
17 | )
18 |
19 | hansard_bill_publications(
20 | ID = NULL,
21 | publication_type = NULL,
22 | start_date = "1900-01-01",
23 | end_date = Sys.Date(),
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = FALSE
28 | )
29 | }
30 | \arguments{
31 | \item{ID}{The ID of a specific bill to return publications for.
32 | If \code{NULL}, returns all bill publications subject to other parameters.
33 | Defaults to \code{NULL}.}
34 |
35 | \item{publication_type}{The type of bill publication to return, in the form
36 | of a string. For a character vector of bill publication types, see
37 | \code{\link[=bill_publication_types]{bill_publication_types()}}. If \code{NULL}, returns all
38 | publications of all types, subject to other parameters.
39 | Defaults to \code{NULL}.}
40 |
41 | \item{start_date}{Only includes bill publications on or after this date.
42 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
43 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
44 | anything else that can be coerced to a date with \code{as.Date()}.
45 | Defaults to \code{'1900-01-01'}.}
46 |
47 | \item{end_date}{Only includes bill publicationson or before this date.
48 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
49 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
50 | anything else that can be coerced to a date with \code{as.Date()}.
51 | Defaults to the current system date.}
52 |
53 | \item{extra_args}{Additional parameters and queries to pass to API. These
54 | queries must be strings and start with "&". See the
55 | \href{http://explore.data.parliament.uk/}{API documentation}
56 | or the package vignette for more details. Defaults to \code{NULL}.}
57 |
58 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
59 | in the tibble to remove special characters and superfluous text, and
60 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
61 |
62 | \item{tidy_style}{The style to convert variable names to, if
63 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
64 | Defaults to \code{'snake'}.}
65 |
66 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
67 | progress of the API request. Defaults to \code{TRUE}.}
68 | }
69 | \value{
70 | A tibble with details on bill publications.
71 | }
72 | \description{
73 | Returns details of all publications associated with a specific bill
74 | or all bills.
75 | }
76 | \examples{
77 | \dontrun{
78 | # Requesting a specific publication
79 | x <- bill_publications(ID = 752025)
80 |
81 | # Requesting all publications after a given date
82 | y <- bill_publications(start_date = "2018-01-01")
83 | }
84 | }
85 | \seealso{
86 | \code{\link[=bill_stage_types]{bill_stage_types()}}
87 |
88 | \code{\link[=bills]{bills()}}
89 |
90 | \code{\link[=bill_publication_types]{bill_publication_types()}}
91 | }
92 |
--------------------------------------------------------------------------------
/man/lord_vote_record.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/lord_vote_record.R
3 | \name{lord_vote_record}
4 | \alias{lord_vote_record}
5 | \alias{hansard_lord_vote_record}
6 | \title{Voting record of members of the House of Lords}
7 | \usage{
8 | lord_vote_record(
9 | peer_id = NULL,
10 | lobby = "all",
11 | start_date = "1900-01-01",
12 | end_date = Sys.Date(),
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = TRUE
17 | )
18 |
19 | hansard_lord_vote_record(
20 | peer_id = NULL,
21 | lobby = "all",
22 | start_date = "1900-01-01",
23 | end_date = Sys.Date(),
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = TRUE
28 | )
29 | }
30 | \arguments{
31 | \item{peer_id}{The ID number of a member of the House of Lords. A value
32 | must be included for this parameter. Use the \code{\link[=lords_members]{lords_members()}}
33 | to find IDs for members of the House of Lords. Defaults to \code{NULL}.}
34 |
35 | \item{lobby}{Accepts one of \code{'all'}, \code{'content'},
36 | \code{'notcontent'}. \code{'content'} returns votes where the peer voted
37 | 'Content', \code{'notcontent'} returns votes where the peer voted
38 | 'Not Content' and \code{'all'} returns all available votes by the peer.
39 | This parameter is not case sensitive. Defaults to \code{'all'}.}
40 |
41 | \item{start_date}{Only includes divisions on or after this date. Accepts
42 | character values in \code{'YYYY-MM-DD'} format, and objects of class
43 | \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or anything
44 | else that can be coerced to a date with \code{as.Date()}.
45 | Defaults to \code{'1900-01-01'}.}
46 |
47 | \item{end_date}{Only includes divisions on or before this date.
48 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
49 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
50 | anything else that can be coerced to a date with \code{as.Date()}.
51 | Defaults to the current system date.}
52 |
53 | \item{extra_args}{Additional parameters and queries to pass to API. These
54 | queries must be strings and start with "&". See the
55 | \href{http://explore.data.parliament.uk/}{API documentation}
56 | or the package vignette for more details. Defaults to \code{NULL}.}
57 |
58 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
59 | in the tibble to remove special characters and superfluous text, and
60 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
61 |
62 | \item{tidy_style}{The style to convert variable names to, if
63 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
64 | Defaults to \code{'snake'}.}
65 |
66 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
67 | progress of the API request. Defaults to \code{TRUE}.}
68 | }
69 | \value{
70 | A tibble with details on the voting record of a
71 | member of the House of Lords.
72 | }
73 | \description{
74 | Accepts an ID number for a member of the House of Commons, and returns a
75 | tibble of their votes.
76 | }
77 | \examples{
78 | \dontrun{
79 | x <- lord_vote_record(530, lobby = "all")
80 |
81 | x <- lord_vote_record(530, lobby = "content")
82 |
83 | x <- lord_vote_record(530, lobby = "notcontent")
84 |
85 | x <- lord_vote_record(530, lobby = "not-content")
86 | # This will also work
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/man/epetition_tibble.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/epetition_tibble.R
3 | \name{epetition_tibble}
4 | \alias{epetition_tibble}
5 | \alias{hansard_epetition_tibble}
6 | \title{Bulk Epetition data}
7 | \usage{
8 | epetition_tibble(
9 | min_signatures = 1,
10 | max_signatures = NULL,
11 | status = NULL,
12 | start_date = "1900-01-01",
13 | end_date = Sys.Date(),
14 | extra_args = NULL,
15 | tidy = TRUE,
16 | tidy_style = "snake",
17 | verbose = TRUE
18 | )
19 |
20 | hansard_epetition_tibble(
21 | min_signatures = 1,
22 | max_signatures = NULL,
23 | status = NULL,
24 | start_date = "1900-01-01",
25 | end_date = Sys.Date(),
26 | extra_args = NULL,
27 | tidy = TRUE,
28 | tidy_style = "snake",
29 | verbose = TRUE
30 | )
31 | }
32 | \arguments{
33 | \item{min_signatures}{The minimum number of signatures required for
34 | inclusion in the tibble. Defaults to 1.}
35 |
36 | \item{max_signatures}{The maximum number of signatures required for
37 | inclusion in the tibble. If \code{NULL}, there is no maximum number of
38 | signatures. Defaults to \code{NULL}.}
39 |
40 | \item{status}{The status of the petition, either \code{'open'} or
41 | \code{'closed'}. If \code{NULL}, returns all petitions both open and
42 | closed. Defaults to \code{NULL}.}
43 |
44 | \item{start_date}{Only includes epetitions created on or after this date.
45 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
46 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
47 | anything else that can be coerced to a date with \code{as.Date()}.
48 | Defaults to \code{'1900-01-01'}.}
49 |
50 | \item{end_date}{Only includes epetitions created on or before this date.
51 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
52 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or a
53 | nything else that can be coerced to a date with \code{as.Date()}.
54 | Defaults to the current system date.}
55 |
56 | \item{extra_args}{Additional parameters and queries to pass to API. These
57 | queries must be strings and start with "&". See the
58 | \href{http://explore.data.parliament.uk/}{API documentation}
59 | or the package vignette for more details. Defaults to \code{NULL}.}
60 |
61 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
62 | in the tibble to remove special characters and superfluous text, and
63 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
64 |
65 | \item{tidy_style}{The style to convert variable names to, if
66 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
67 | Defaults to \code{'snake'}.}
68 |
69 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
70 | progress of the API request. Defaults to \code{TRUE}.}
71 | }
72 | \value{
73 | A tibble with details on electronic petitions
74 | submitted to parliament.
75 | }
76 | \description{
77 | Get data on all epetitions submitted to parliament, with the label, sponsor,
78 | number of signatures, date created and epetition ID. For greater detail on
79 | indidivual epetitions, see \code{\link[=epetition]{epetition()}}.
80 | }
81 | \examples{
82 | \dontrun{
83 | x <- epetition_tibble()
84 |
85 | y <- epetition_tibble(max_signatures = 500)
86 |
87 | z <- epetition_tibble(start_date = "2016-12-01", end_date = "2017-04-25")
88 | }
89 |
90 | }
91 | \seealso{
92 | \code{\link[=epetition]{epetition()}}
93 | }
94 |
--------------------------------------------------------------------------------
/man/mp_questions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mp_questions.R
3 | \name{mp_questions}
4 | \alias{mp_questions}
5 | \alias{hansard_mp_questions}
6 | \title{Questions asked by a given MP or MPs}
7 | \usage{
8 | mp_questions(
9 | mp_id = NULL,
10 | question_type = "all",
11 | start_date = "1900-01-01",
12 | end_date = Sys.Date(),
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = TRUE
17 | )
18 |
19 | hansard_mp_questions(
20 | mp_id = NULL,
21 | question_type = "all",
22 | start_date = "1900-01-01",
23 | end_date = Sys.Date(),
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = TRUE
28 | )
29 | }
30 | \arguments{
31 | \item{mp_id}{The ID number of a member of the House of Commons, or a vector
32 | of IDs. Defaults to \code{NULL}.}
33 |
34 | \item{question_type}{Accepts the arguments \code{'all'}, \code{'oral'} and
35 | \code{'written'}. This parameter is not case sensitive.
36 | Defaults to \code{'all'}.}
37 |
38 | \item{start_date}{Only includes questions answered on or after this date.
39 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
40 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
41 | anything else that can be coerced to a date with \code{as.Date()}.
42 | Defaults to \code{'1900-01-01'}.}
43 |
44 | \item{end_date}{Only includes questions answered on or before this date.
45 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
46 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
47 | anything else that can be coerced to a date with \code{as.Date()}.
48 | Defaults to the current system date.}
49 |
50 | \item{extra_args}{Additional parameters and queries to pass to API. These
51 | queries must be strings and start with "&". See the
52 | \href{http://explore.data.parliament.uk/}{API documentation}
53 | or the package vignette for more details. Defaults to \code{NULL}.}
54 |
55 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
56 | in the tibble to remove special characters and superfluous text, and
57 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
58 |
59 | \item{tidy_style}{The style to convert variable names to, if
60 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
61 | Defaults to \code{'snake'}.}
62 |
63 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
64 | progress of the API request. Defaults to \code{TRUE}.}
65 | }
66 | \value{
67 | A tibble with details on all questions asked by a
68 | member of the House of Commons.
69 | }
70 | \description{
71 | Accepts an ID number for a member of the House of Commons, and returns a
72 | tibble of of all their oral and written questions.
73 | }
74 | \examples{
75 | \dontrun{
76 | x <- mp_questions(c(172, 3967), "all")
77 |
78 | y <- mp_questions(mp_id = 172, question_type = "all")
79 |
80 | z <- mp_questions(c(172, 3967), "written")
81 | }
82 |
83 | }
84 | \seealso{
85 | \code{\link[=all_answered_questions]{all_answered_questions()}}
86 |
87 | \code{\link[=commons_answered_questions]{commons_answered_questions()}}
88 |
89 | \code{\link[=commons_oral_questions]{commons_oral_questions()}}
90 |
91 | \code{\link[=commons_oral_question_times]{commons_oral_question_times()}}
92 |
93 | \code{\link[=commons_written_questions]{commons_written_questions()}}
94 |
95 | \code{\link[=lords_written_questions]{lords_written_questions()}}
96 | }
97 |
--------------------------------------------------------------------------------
/R/commons_oral_questions.R:
--------------------------------------------------------------------------------
1 |
2 |
3 | #' House of Commons Oral Questions
4 | #'
5 | #' Imports data on House of Commons oral questions, based on the asking MP,
6 | #' the answering department and the date. The `mp_id` and
7 | #' `answering_department` parameters accept a single ID or department
8 | #' names, or a list of IDs or department names, respectively.
9 | #'
10 | #' @param mp_id The ID of a given MP asking an oral question, or a list of
11 | #' MP Ids. Defaults to `NULL`.
12 | #'
13 | #' @param answering_department The name of a department, or a list of
14 | #' departments. Defaults to `NULL`.
15 | #'
16 | #' @param start_date Only includes questions answered on or after this date.
17 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
18 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or anything
19 | #' else that can be coerced to a date with `as.Date()`. ]
20 | #' Defaults to `'1900-01-01'`.
21 | #'
22 | #' @param end_date Only includes questions answered on or before this date.
23 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of class
24 | #' `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or anything else
25 | #' that can be coerced to a date with `as.Date()`. Defaults to the current
26 | #' system date.
27 | #' @inheritParams all_answered_questions
28 | #' @return A tibble with details on all oral questions in the House of Commons.
29 | #' @seealso [all_answered_questions()]
30 | #' @seealso [commons_answered_questions()]
31 | #' @seealso [commons_oral_question_times()]
32 | #' @seealso [commons_written_questions()]
33 | #' @seealso [lords_written_questions()]
34 | #' @seealso [mp_questions()]
35 | #' @export
36 | #' @examples
37 | #' \dontrun{
38 | #'
39 | #' # Oral questions from a single MP to a single department
40 | #' x <- commons_oral_questions(mp_id = 4019, answering_department = "education")
41 | #'
42 | #'
43 | #' ## Questions from multiple MPs and to multiple departments
44 | #' y <- commons_oral_questions(
45 | #' mp_id = c(4019, 4051, 4588),
46 | #' answering_department = c("education", "health")
47 | #' )
48 | #' }
49 | #'
50 | commons_oral_questions <- function(mp_id = NULL, answering_department = NULL,
51 | start_date = "1900-01-01",
52 | end_date = Sys.Date(),
53 | extra_args = NULL, tidy = TRUE,
54 | tidy_style = "snake", verbose = TRUE) {
55 | if (length(mp_id) > 1 || length(answering_department) > 1) {
56 | df <- commons_oral_questions_multi(
57 | mp_id, answering_department,
58 | start_date, end_date,
59 | extra_args, verbose
60 | )
61 | } else {
62 | dates <- paste0(
63 | "&_properties=AnswerDate&max-AnswerDate=",
64 | as.Date(end_date),
65 | "&min-AnswerDate=",
66 | as.Date(start_date)
67 | )
68 |
69 | json_query <- question_query_construction(mp_id, answering_department)
70 |
71 | query <- paste0(
72 | url_util, "commonsoralquestions", json_query, dates, extra_args
73 | )
74 |
75 | df <- loop_query(query, verbose) # in utils-loop.R
76 | }
77 |
78 | if (nrow(df) == 0) {
79 | message("The request did not return any data.
80 | Please check your parameters.")
81 | } else {
82 | if (tidy) {
83 | df <- coq_tidy(df, tidy_style) ## in utils-commons.R
84 | }
85 |
86 | df
87 | }
88 | }
89 |
90 |
91 | #' @rdname commons_oral_questions
92 | #' @export
93 | hansard_commons_oral_questions <- commons_oral_questions
94 |
--------------------------------------------------------------------------------
/R/election_candidates.R:
--------------------------------------------------------------------------------
1 |
2 | #' Election candidate details
3 | #'
4 | #' Returns the name and party of all candidates standing in an election, for
5 | #' each constituency. Note that for general elections this can return a very
6 | #' large tibble with hundreds of variables.
7 | #'
8 | #'
9 | #' @param ID Accepts an ID for a general or by-election from the 2010 General
10 | #' Election onwards, and returns the results. If `NULL`, returns all
11 | #' available election results. Defaults to `NULL`.
12 | #'
13 | #' @param constit_details If `TRUE`, returns additional details on each
14 | #' constituency, including its GSS (Government Statistical Service) code.
15 | #' Defaults to `FALSE`.
16 | #' @inheritParams all_answered_questions
17 | #' @export
18 | #' @seealso [elections()]
19 | #' @seealso [election_results()]
20 | #'
21 | #' @examples
22 | #' \dontrun{
23 | #' x <- election_candidates(ID = 382037)
24 | #'
25 | #' y <- election_candidates()
26 | #'
27 | #' z <- election_candidates(constit_details = TRUE)
28 | #' }
29 | #'
30 | election_candidates <- function(ID = NULL, constit_details = FALSE,
31 | extra_args = NULL, tidy = TRUE,
32 | tidy_style = "snake", verbose = TRUE) {
33 | id_query <- ifelse(
34 | !is.null(ID),
35 | paste0("electionId=", ID),
36 | ""
37 | )
38 |
39 | query <- paste0(url_util, "electionresults.json?", id_query, extra_args)
40 |
41 | df <- loop_query(query, verbose) # in utils-loop.R
42 |
43 | names(df)[names(df) == "_about"] <- "election_about"
44 |
45 | dat <- vector("list", nrow(df))
46 |
47 | df$election_about <- gsub(
48 | "http://data.parliament.uk/resources/", "",
49 | df$election_about
50 | )
51 |
52 | seq_list <- seq(from = 1, to = nrow(df), by = 1)
53 |
54 | for (i in seq_along(seq_list)) {
55 | x <- jsonlite::fromJSON(
56 | paste0(
57 | "http://lda.data.parliament.uk/electionresults/",
58 | df$election_about[[i]], ".json"
59 | ),
60 | flatten = TRUE
61 | )
62 |
63 | df2 <- x$result$primaryTopic$candidate
64 |
65 | names(df2)[names(df2) == "_about"] <- "election_about"
66 |
67 | df2$election_about <- gsub(
68 | "http://data.parliament.uk/resources/",
69 | "", df2$election_about
70 | )
71 |
72 | df2$election_about <- gsub("/.*", "", df2$election_about)
73 |
74 | dat[[i]] <- df2
75 |
76 | if (verbose) {
77 | message(
78 | "Retrieving ", i, " of ", nrow(df), ": ",
79 | df$constituency.label._value[[i]], ", ",
80 | df$election.label._value[[i]]
81 | )
82 | }
83 | }
84 |
85 | df4 <- dplyr::bind_rows(dat)
86 |
87 | if (constit_details == TRUE & (nrow(df) > 0)) {
88 | message("Retrieving constituency information")
89 |
90 | constits <- suppressMessages(constituencies(current = FALSE))
91 |
92 | df <- dplyr::left_join(df, constits,
93 | by = c(constituency._about = "about")
94 | )
95 | }
96 |
97 |
98 | if (nrow(df) == 0) {
99 | message("The request did not return any data.
100 | Please check your parameters.")
101 | } else {
102 | df <- tibble::as_tibble(df)
103 |
104 | df <- dplyr::left_join(df, df4, by = "election_about")
105 |
106 | if (tidy) {
107 | df <- elect_can_tidy(df, tidy_style)
108 | }
109 |
110 | df
111 | }
112 | }
113 |
114 |
115 | #' @rdname election_candidates
116 | #' @export
117 | hansard_election_candidates <- election_candidates
118 |
--------------------------------------------------------------------------------
/R/commons_oral_question_times.R:
--------------------------------------------------------------------------------
1 |
2 | #' Commons oral question times
3 | #'
4 | #' Imports data on House of Commons oral question times. Query with parameters
5 | #' for the parliamentary session or the question ID. If `tidy=TRUE`,
6 | #' datetime variables are converted to `POSIXct` class.
7 | #'
8 | #'
9 | #' @param session Accepts a session in format `yyyy/yy`
10 | #' (e.g. `"2016/17"`) and returns a tibble of all oral question times from
11 | #' that session. Defaults to `NULL`.
12 | #'
13 | #' @param question_id Accepts a question time ID, and returns a tibble of
14 | #' that question time.
15 | #' @inheritParams all_answered_questions
16 | #' @return A tibble with information on oral question times in the House of
17 | #' Commons.
18 | #' @seealso [all_answered_questions()]
19 | #' @seealso [commons_answered_questions()]
20 | #' @seealso [commons_oral_questions()]
21 | #' @seealso [commons_written_questions()]
22 | #' @seealso [lords_written_questions()]
23 | #' @seealso [mp_questions()]
24 | #' @export
25 | #' @examples
26 | #' \dontrun{
27 | #' x <- commons_oral_question_times(session = "2016/17", question_id = "685697")
28 | #' }
29 | #'
30 | commons_oral_question_times <- function(session = NULL, question_id = NULL,
31 | extra_args = NULL, tidy = TRUE,
32 | tidy_style = "snake",
33 | verbose = TRUE) {
34 | if (!is.null(session)) {
35 | session_query <- utils::URLencode(paste0("session=", session))
36 | } else {
37 | session_query <- ""
38 | }
39 |
40 | if (!is.null(question_id)) {
41 | question_query <- paste0("/", question_id)
42 | } else {
43 | question_query <- ""
44 | }
45 |
46 | query <- paste0(
47 | url_util, "commonsoralquestiontimes", question_query,
48 | ".json?", session_query, extra_args
49 | )
50 |
51 | if (is.null(question_id)) {
52 | df <- loop_query(query, verbose) # in utils-loop.R
53 | } else {
54 | veb(verbose)
55 |
56 | mydata <- jsonlite::fromJSON(query, flatten = TRUE)
57 |
58 | df <- tibble::tibble(
59 | `_about` = mydata$result$primaryTopic$`_about`,
60 | AnswerBody = list(mydata$result$primaryTopic$AnswerBody),
61 | session = mydata$result$primaryTopic$session,
62 | title = mydata$result$primaryTopic$title,
63 | AnswerDateTime._value =
64 | mydata$result$primaryTopic$AnswerDateTime$`_value`,
65 | AnswerDateTime._datatype =
66 | mydata$result$primaryTopic$AnswerDateTime$`_datatype`,
67 | Location._about = mydata$result$primaryTopic$Location$`_about`,
68 | Location.prefLabel._value =
69 | mydata$result$primaryTopic$Location$prefLabel$`_value`,
70 | QuestionType._value =
71 | mydata$result$primaryTopic$QuestionType$`_value`,
72 | date._value = mydata$result$primaryTopic$date$`_value`,
73 | date._datatype = mydata$result$primaryTopic$date$`_datatype`,
74 | modified._value = mydata$result$primaryTopic$modified$`_value`,
75 | modified._datatype = mydata$result$primaryTopic$modified$`_datatype`,
76 | sessionNumber._value =
77 | mydata$result$primaryTopic$sessionNumber$`_value`
78 | )
79 | }
80 |
81 | if (nrow(df) == 0) {
82 | message("The request did not return any data.
83 | Please check your parameters.")
84 | } else {
85 | if (tidy) {
86 | df <- coqt_tidy(df, tidy_style) ## in utils-commons.R
87 | }
88 |
89 | df
90 | }
91 | }
92 |
93 | #' @rdname commons_oral_question_times
94 | #' @export
95 |
96 | hansard_commons_oral_question_times <- commons_oral_question_times
97 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # hansard: Accessing Westminster Parliament Data
5 |
6 |
7 |
8 | [](https://opensource.org/licenses/MIT)
10 | [](https://cran.r-project.org/package=hansard)
11 | [](https://github.com/evanodell/hansard)
13 | [](https://cran.r-project.org/package=hansard)
15 | [](https://zenodo.org/badge/latestdoi/72111315)
16 | [](https://github.com/EvanOdell/hansard/actions)
18 | [](https://codecov.io/gh/EvanOdell/hansard?branch=master)
20 | [](https://github.com/EvanOdell/hansard/actions)
21 | [](https://ci.appveyor.com/project/EvanOdell/hansard)
23 |
24 |
25 | An R package to automatically fetch data from the UK Parliament API.
26 | Ironically, Hansard data (as in speeches) is not yet accessible through
27 | the API. To explore all available data see
28 | . Documentation for the API itself is
29 | available [here](http://explore.data.parliament.uk/).
30 |
31 | Like the UK parliament API, this package is a work in progress.
32 | Additional functionalities will be added to the package as they are
33 | developed in the API. The most up-to-date documentation for this package
34 | will always be available at .
35 |
36 | To install from CRAN run:
37 |
38 | install.packages("hansard")
39 |
40 | To install the development version run:
41 |
42 | #install.packages("remotes")
43 | remotes::install_github("evanodell/hansard")
44 |
45 | ## Using hansard
46 |
47 | For an introduction to `hansard`, please see the
48 | [vignette](https://docs.evanodell.com/hansard/articles/introduction.html).
49 |
50 | ## Citing hansard
51 |
52 | Please cite this package as:
53 |
54 | Odell E (2017). *hansard: Provides Easy Downloading Capabilities for the
55 | UK Parliament API*. doi:
56 | [10.5281/zenodo.591264](https://doi.org/10.5281/zenodo.591264), R
57 | package version 0.8.0.9000, URL:
58 | .
59 |
60 | A BibTeX entry for LaTeX users is
61 |
62 | @Manual{,
63 | title = {{hansard}: Provides Easy Downloading Capabilities for the UK Parliament API},
64 | author = {Evan Odell},
65 | note = {R package version 0.8.0.9000},
66 | doi = {10.5281/zenodo.591264},
67 | url = {https://cran.r-project.org/package=hansard},
68 | }
69 |
70 | ### Disclaimer
71 |
72 | This package is in no way officially related to or endorsed by the UK
73 | Parliamentary Data Service. It is released under an MIT license. Please
74 | note that this project is released with a [Contributor Code of
75 | Conduct](https://github.com/evanodell/hansard/blob/master/CODE_OF_CONDUCT.md).
76 | By participating in this project you agree to abide by its terms.
77 |
78 | Data obtained through the `hansard` package is licensed under the Open
79 | Government License. The code in `hansard` uses the MIT license.
80 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | export(all_answered_questions)
4 | export(bill_publications)
5 | export(bill_stage_types)
6 | export(bills)
7 | export(commons_answered_questions)
8 | export(commons_division_date)
9 | export(commons_divisions)
10 | export(commons_members)
11 | export(commons_oral_question_times)
12 | export(commons_oral_questions)
13 | export(commons_terms)
14 | export(commons_written_questions)
15 | export(constituencies)
16 | export(early_day_motions)
17 | export(edm_text)
18 | export(election_candidates)
19 | export(election_results)
20 | export(elections)
21 | export(epetition)
22 | export(epetition_tibble)
23 | export(hansard_all_answered_questions)
24 | export(hansard_bill_publications)
25 | export(hansard_bill_stage_types)
26 | export(hansard_bills)
27 | export(hansard_commons_answered_questions)
28 | export(hansard_commons_division_date)
29 | export(hansard_commons_divisions)
30 | export(hansard_commons_members)
31 | export(hansard_commons_oral_question_times)
32 | export(hansard_commons_oral_questions)
33 | export(hansard_commons_terms)
34 | export(hansard_commons_written_questions)
35 | export(hansard_constituencies)
36 | export(hansard_early_day_motions)
37 | export(hansard_election_candidates)
38 | export(hansard_election_results)
39 | export(hansard_elections)
40 | export(hansard_epetition)
41 | export(hansard_epetition_tibble)
42 | export(hansard_lord_vote_record)
43 | export(hansard_lords_amendments)
44 | export(hansard_lords_attendance_date)
45 | export(hansard_lords_attendance_session)
46 | export(hansard_lords_divisions)
47 | export(hansard_lords_interests)
48 | export(hansard_lords_members)
49 | export(hansard_lords_sessions)
50 | export(hansard_lords_written_questions)
51 | export(hansard_members)
52 | export(hansard_members_search)
53 | export(hansard_mp_edms)
54 | export(hansard_mp_questions)
55 | export(hansard_mp_vote_record)
56 | export(hansard_papers_laid)
57 | export(hansard_publication_logs)
58 | export(hansard_research_briefings)
59 | export(hansard_research_subtopics_list)
60 | export(hansard_research_topics_list)
61 | export(hansard_research_types_list)
62 | export(hansard_sessions_info)
63 | export(hansard_tv_channels)
64 | export(hansard_tv_clips)
65 | export(hansard_tv_programmes)
66 | export(lord_vote_record)
67 | export(lords_amendments)
68 | export(lords_attendance_date)
69 | export(lords_attendance_session)
70 | export(lords_divisions)
71 | export(lords_interests)
72 | export(lords_members)
73 | export(lords_sessions)
74 | export(lords_written_questions)
75 | export(members)
76 | export(members_search)
77 | export(mp_edms)
78 | export(mp_questions)
79 | export(mp_vote_record)
80 | export(papers_laid)
81 | export(publication_logs)
82 | export(research_briefings)
83 | export(research_subtopics_list)
84 | export(research_topics_list)
85 | export(research_types_list)
86 | export(sessions_info)
87 | export(tv_channels)
88 | export(tv_clips)
89 | export(tv_programmes)
90 | importFrom(dplyr,bind_rows)
91 | importFrom(dplyr,distinct)
92 | importFrom(dplyr,group_by_at)
93 | importFrom(dplyr,grouped_df)
94 | importFrom(dplyr,left_join)
95 | importFrom(dplyr,n)
96 | importFrom(dplyr,summarise)
97 | importFrom(dplyr,summarise_all)
98 | importFrom(httr,GET)
99 | importFrom(httr,content)
100 | importFrom(httr,http_type)
101 | importFrom(httr,status_code)
102 | importFrom(jsonlite,fromJSON)
103 | importFrom(lubridate,parse_date_time)
104 | importFrom(snakecase,to_any_case)
105 | importFrom(tibble,as_tibble)
106 | importFrom(tidyr,spread)
107 | importFrom(tidyr,unnest)
108 | importFrom(tidyr,unnest_wider)
109 |
--------------------------------------------------------------------------------
/man/commons_written_questions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/commons_written_questions.R
3 | \name{commons_written_questions}
4 | \alias{commons_written_questions}
5 | \alias{hansard_commons_written_questions}
6 | \title{House of Commons Written Questions}
7 | \usage{
8 | commons_written_questions(
9 | mp_id = NULL,
10 | answering_department = NULL,
11 | start_date = "1900-01-01",
12 | end_date = Sys.Date(),
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = TRUE
17 | )
18 |
19 | hansard_commons_written_questions(
20 | mp_id = NULL,
21 | answering_department = NULL,
22 | start_date = "1900-01-01",
23 | end_date = Sys.Date(),
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = TRUE
28 | )
29 | }
30 | \arguments{
31 | \item{mp_id}{Accepts a member ID or a list of member IDs and returns a
32 | tibble with all written questions asked by that MP or list of MPs. If
33 | \code{NULL}, mp_id is not included as a query parameter.
34 | Defaults to \code{NULL}.}
35 |
36 | \item{answering_department}{Accepts a string with a department name or
37 | partial name, or a list of such strings. The query acts as a search, so
38 | passing \code{'health'} will return all questions answered by the
39 | Department of Health. If \code{NULL}, answering_department is not included
40 | as a query parameter. Defaults to \code{NULL}.}
41 |
42 | \item{start_date}{Only includes questions tabled on or after this date.
43 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
44 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
45 | anything else that can be coerced to a date with \code{as.Date()}.
46 | Defaults to \code{'1900-01-01'}.}
47 |
48 | \item{end_date}{Only includes questions tabled on or before this date.
49 | Accepts character values in \code{'YYYY-MM-DD'} format, and objects of
50 | class \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or
51 | anything else that can be coerced to a date with \code{as.Date()}.
52 | Defaults to the current system date.}
53 |
54 | \item{extra_args}{Additional parameters and queries to pass to API. These
55 | queries must be strings and start with "&". See the
56 | \href{http://explore.data.parliament.uk/}{API documentation}
57 | or the package vignette for more details. Defaults to \code{NULL}.}
58 |
59 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
60 | in the tibble to remove special characters and superfluous text, and
61 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
62 |
63 | \item{tidy_style}{The style to convert variable names to, if
64 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
65 | Defaults to \code{'snake'}.}
66 |
67 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
68 | progress of the API request. Defaults to \code{TRUE}.}
69 | }
70 | \value{
71 | A tibble with details on written questions in the House of Commons.
72 | }
73 | \description{
74 | Imports data in a tibble on House of Commons written questions.
75 | }
76 | \examples{
77 | \dontrun{
78 | # Returns a tibble with written questions from Jon Trickett,
79 | # answered by the Cabinet Office.
80 | x <- commons_written_questions(
81 | mp_id = 410,
82 | answering_department = "cabinet office"
83 | )
84 |
85 | # Returns a tibble with written questions from Jon Trickett or Diane Abbott,
86 | # and answered by the Cabinet Office or the Home Office.
87 | x <- commons_written_questions(
88 | mp_id = c(410, 172),
89 | answering_department = c("cabinet", "home")
90 | )
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/R/commons_written_questions.R:
--------------------------------------------------------------------------------
1 |
2 | #' House of Commons Written Questions
3 | #'
4 | #' Imports data in a tibble on House of Commons written questions.
5 | #'
6 | #'
7 | #' @param mp_id Accepts a member ID or a list of member IDs and returns a
8 | #' tibble with all written questions asked by that MP or list of MPs. If
9 | #' `NULL`, mp_id is not included as a query parameter.
10 | #' Defaults to `NULL`.
11 | #'
12 | #' @param answering_department Accepts a string with a department name or
13 | #' partial name, or a list of such strings. The query acts as a search, so
14 | #' passing `'health'` will return all questions answered by the
15 | #' Department of Health. If `NULL`, answering_department is not included
16 | #' as a query parameter. Defaults to `NULL`.
17 | #'
18 | #' @param start_date Only includes questions tabled on or after this date.
19 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
20 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
21 | #' anything else that can be coerced to a date with `as.Date()`.
22 | #' Defaults to `'1900-01-01'`.
23 | #'
24 | #' @param end_date Only includes questions tabled on or before this date.
25 | #' Accepts character values in `'YYYY-MM-DD'` format, and objects of
26 | #' class `Date`, `POSIXt`, `POSIXct`, `POSIXlt` or
27 | #' anything else that can be coerced to a date with `as.Date()`.
28 | #' Defaults to the current system date.
29 | #' @inheritParams all_answered_questions
30 | #' @return A tibble with details on written questions in the House of Commons.
31 | #' @export
32 | #' @examples
33 | #' \dontrun{
34 | #' # Returns a tibble with written questions from Jon Trickett,
35 | #' # answered by the Cabinet Office.
36 | #' x <- commons_written_questions(
37 | #' mp_id = 410,
38 | #' answering_department = "cabinet office"
39 | #' )
40 | #'
41 | #' # Returns a tibble with written questions from Jon Trickett or Diane Abbott,
42 | #' # and answered by the Cabinet Office or the Home Office.
43 | #' x <- commons_written_questions(
44 | #' mp_id = c(410, 172),
45 | #' answering_department = c("cabinet", "home")
46 | #' )
47 | #' }
48 | #'
49 | commons_written_questions <- function(mp_id = NULL,
50 | answering_department = NULL,
51 | start_date = "1900-01-01",
52 | end_date = Sys.Date(),
53 | extra_args = NULL,
54 | tidy = TRUE,
55 | tidy_style = "snake",
56 | verbose = TRUE) {
57 | ## For lists queries
58 | if (length(mp_id) > 1 || length(answering_department) > 1) {
59 | df <- commons_written_questions_multi(
60 | mp_id, answering_department,
61 | start_date, end_date,
62 | extra_args, verbose
63 | )
64 | } else {
65 | dates <- paste0(
66 | "&_properties=dateTabled&max-dateTabled=",
67 | as.Date(end_date),
68 | "&min-dateTabled=",
69 | as.Date(start_date)
70 | )
71 |
72 | json_query <- question_query_construction(mp_id, answering_department)
73 |
74 | query <- paste0(
75 | url_util, "commonswrittenquestions", json_query, dates, extra_args
76 | )
77 |
78 | df <- loop_query(query, verbose) # in utils-loop.R
79 | }
80 |
81 | if (nrow(df) == 0) {
82 | message("The request did not return any data.
83 | Please check your parameters.")
84 | } else {
85 | if (tidy) {
86 | df <- cwq_tidy(df, tidy_style) ## in utils-commons.R
87 | }
88 |
89 | df
90 | }
91 | }
92 |
93 |
94 | #' @rdname commons_written_questions
95 | #' @export
96 | hansard_commons_written_questions <- commons_written_questions
97 |
--------------------------------------------------------------------------------
/man/commons_divisions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/commons_divisions.R
3 | \name{commons_divisions}
4 | \alias{commons_divisions}
5 | \alias{hansard_commons_divisions}
6 | \title{House of Commons divisions}
7 | \usage{
8 | commons_divisions(
9 | division_id = NULL,
10 | division_uin = NULL,
11 | summary = FALSE,
12 | start_date = "1900-01-01",
13 | end_date = Sys.Date(),
14 | extra_args = NULL,
15 | tidy = TRUE,
16 | tidy_style = "snake",
17 | verbose = TRUE
18 | )
19 |
20 | hansard_commons_divisions(
21 | division_id = NULL,
22 | division_uin = NULL,
23 | summary = FALSE,
24 | start_date = "1900-01-01",
25 | end_date = Sys.Date(),
26 | extra_args = NULL,
27 | tidy = TRUE,
28 | tidy_style = "snake",
29 | verbose = TRUE
30 | )
31 | }
32 | \arguments{
33 | \item{division_id}{The id of a particular vote. If empty, returns a
34 | tibble with information on all commons divisions, subject to all other
35 | parameters. Defaults to \code{NULL}. Only accepts a single division ID
36 | at a time, but to return details on a list of division IDs use with
37 | \code{lapply}. The \code{division_id} takes priority over the \code{division_uid} parameter.}
38 |
39 | \item{division_uin}{The UIN of a particular vote. If empty, returns a
40 | tibble with information on all commons divisions, subject to all other
41 | parameters. Defaults to \code{NULL}. Only accepts a single division UIN
42 | at a time, but to return details on a list of division UINs use with
43 | \code{lapply}.}
44 |
45 | \item{summary}{If \code{TRUE}, returns a small tibble summarising a
46 | division outcome. Otherwise returns a tibble with details on how each
47 | MP voted. Has no effect if \code{division_id} is empty. Defaults to \code{FALSE}.}
48 |
49 | \item{start_date}{Only includes divisions on or after this date. Accepts
50 | character values in \code{'YYYY-MM-DD'} format, and objects of class
51 | \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or anything
52 | else that can be coerced to a date with \code{as.Date()}. Defaults
53 | to \code{'1900-01-01'}.}
54 |
55 | \item{end_date}{Only includes divisions on or before this date. Accepts
56 | character values in \code{'YYYY-MM-DD'} format, and objects of class
57 | \code{Date}, \code{POSIXt}, \code{POSIXct}, \code{POSIXlt} or anything
58 | else that can be coerced to a date with \code{as.Date()}. Defaults to
59 | the current system date.}
60 |
61 | \item{extra_args}{Additional parameters and queries to pass to API. These
62 | queries must be strings and start with "&". See the
63 | \href{http://explore.data.parliament.uk/}{API documentation}
64 | or the package vignette for more details. Defaults to \code{NULL}.}
65 |
66 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
67 | in the tibble to remove special characters and superfluous text, and
68 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
69 |
70 | \item{tidy_style}{The style to convert variable names to, if
71 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
72 | Defaults to \code{'snake'}.}
73 |
74 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
75 | progress of the API request. Defaults to \code{TRUE}.}
76 | }
77 | \value{
78 | A tibble with the results of divisions in the House of Commons.
79 | }
80 | \description{
81 | Imports data on House of Commons divisions (votes), either full details
82 | on how each member voted, or a summary of vote totals.
83 | }
84 | \examples{
85 | \dontrun{
86 |
87 | ## All commons divisions
88 | x <- commons_divisions()
89 |
90 | ## Vote breakdown of specific commons division
91 | y <- commons_divisions(division_id = 694163, summary = FALSE)
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/man/election_results.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/election_results.R
3 | \name{election_results}
4 | \alias{election_results}
5 | \alias{hansard_election_results}
6 | \title{General and By-Election Results}
7 | \usage{
8 | election_results(
9 | ID = NULL,
10 | all_data = FALSE,
11 | calculate_percent = FALSE,
12 | constit_details = FALSE,
13 | extra_args = NULL,
14 | tidy = TRUE,
15 | tidy_style = "snake",
16 | verbose = TRUE
17 | )
18 |
19 | hansard_election_results(
20 | ID = NULL,
21 | all_data = FALSE,
22 | calculate_percent = FALSE,
23 | constit_details = FALSE,
24 | extra_args = NULL,
25 | tidy = TRUE,
26 | tidy_style = "snake",
27 | verbose = TRUE
28 | )
29 | }
30 | \arguments{
31 | \item{ID}{Accepts an ID for a general or by-election from the 2010 General
32 | Election onwards, and returns the results. If \code{NULL}, returns all
33 | available election results. Defaults to \code{NULL}.}
34 |
35 | \item{all_data}{If \code{TRUE}, returns vote share for all parties standing
36 | in any constituency in the election/elections returned. Defaults to
37 | \code{FALSE}. Note that aside from shorthand for the Conservatives, Labour,
38 | Liberal Democrat and Independent (Con, Lab, Lib and Ind, respectively)
39 | being converted to their full names, party names are not tidied, so will
40 | contain spaces in the case of parties with multiple words in their name,
41 | such as the Liberal Democrats. If a party did not stand in a constituency
42 | its vote count is listed as NA. There is a drawback to using this parameter,
43 | as multiple candidates from the same party in a constituency, or multiple
44 | independent candidates, have their vote totals combined.}
45 |
46 | \item{calculate_percent}{If \code{TRUE}, calculates the turnout percentage
47 | for each constituency in the tibble and the majority of the winning
48 | candidate to one decimal place, and includes this information in the
49 | tibble in additional columns labelled 'turnout_percentage' and
50 | 'majority_percentage'. Defaults to \code{FALSE}.}
51 |
52 | \item{constit_details}{If \code{TRUE}, returns additional details on each
53 | constituency, including its GSS (Government Statistical Service) code.
54 | Defaults to \code{FALSE}.}
55 |
56 | \item{extra_args}{Additional parameters and queries to pass to API. These
57 | queries must be strings and start with "&". See the
58 | \href{http://explore.data.parliament.uk/}{API documentation}
59 | or the package vignette for more details. Defaults to \code{NULL}.}
60 |
61 | \item{tidy}{Logical parameter. If \code{TRUE}, fixes the variable names
62 | in the tibble to remove special characters and superfluous text, and
63 | converts the variable names to a consistent style. Defaults to \code{TRUE}.}
64 |
65 | \item{tidy_style}{The style to convert variable names to, if
66 | \code{tidy = TRUE}. Accepts any style accepted by \link[snakecase]{to_any_case}.
67 | Defaults to \code{'snake'}.}
68 |
69 | \item{verbose}{If \code{TRUE}, displayes messages on the console on the
70 | progress of the API request. Defaults to \code{TRUE}.}
71 | }
72 | \value{
73 | A tibble with the results of all general and by-elections, or of
74 | a specified general election or by-election.
75 | }
76 | \description{
77 | Imports results from general and by-elections from the
78 | 2010 General Election onwards.
79 | }
80 | \examples{
81 | \dontrun{
82 | x <- election_results(ID = 382037)
83 |
84 | y <- election_results()
85 |
86 | z <- election_results(calculate_percent = TRUE, constit_details = TRUE)
87 |
88 | w <- election_results(ID = 730039, all_data = TRUE)
89 | }
90 |
91 | }
92 | \seealso{
93 | \code{\link[=elections]{elections()}}
94 |
95 | \code{\link[=election_candidates]{election_candidates()}}
96 | }
97 |
--------------------------------------------------------------------------------
/docs/pkgdown.js:
--------------------------------------------------------------------------------
1 | /* http://gregfranko.com/blog/jquery-best-practices/ */
2 | (function($) {
3 | $(function() {
4 |
5 | $('.navbar-fixed-top').headroom();
6 |
7 | $('body').css('padding-top', $('.navbar').height() + 10);
8 | $(window).resize(function(){
9 | $('body').css('padding-top', $('.navbar').height() + 10);
10 | });
11 |
12 | $('[data-toggle="tooltip"]').tooltip();
13 |
14 | var cur_path = paths(location.pathname);
15 | var links = $("#navbar ul li a");
16 | var max_length = -1;
17 | var pos = -1;
18 | for (var i = 0; i < links.length; i++) {
19 | if (links[i].getAttribute("href") === "#")
20 | continue;
21 | // Ignore external links
22 | if (links[i].host !== location.host)
23 | continue;
24 |
25 | var nav_path = paths(links[i].pathname);
26 |
27 | var length = prefix_length(nav_path, cur_path);
28 | if (length > max_length) {
29 | max_length = length;
30 | pos = i;
31 | }
32 | }
33 |
34 | // Add class to parent , and enclosing if in dropdown
35 | if (pos >= 0) {
36 | var menu_anchor = $(links[pos]);
37 | menu_anchor.parent().addClass("active");
38 | menu_anchor.closest("li.dropdown").addClass("active");
39 | }
40 | });
41 |
42 | function paths(pathname) {
43 | var pieces = pathname.split("/");
44 | pieces.shift(); // always starts with /
45 |
46 | var end = pieces[pieces.length - 1];
47 | if (end === "index.html" || end === "")
48 | pieces.pop();
49 | return(pieces);
50 | }
51 |
52 | // Returns -1 if not found
53 | function prefix_length(needle, haystack) {
54 | if (needle.length > haystack.length)
55 | return(-1);
56 |
57 | // Special case for length-0 haystack, since for loop won't run
58 | if (haystack.length === 0) {
59 | return(needle.length === 0 ? 0 : -1);
60 | }
61 |
62 | for (var i = 0; i < haystack.length; i++) {
63 | if (needle[i] != haystack[i])
64 | return(i);
65 | }
66 |
67 | return(haystack.length);
68 | }
69 |
70 | /* Clipboard --------------------------*/
71 |
72 | function changeTooltipMessage(element, msg) {
73 | var tooltipOriginalTitle=element.getAttribute('data-original-title');
74 | element.setAttribute('data-original-title', msg);
75 | $(element).tooltip('show');
76 | element.setAttribute('data-original-title', tooltipOriginalTitle);
77 | }
78 |
79 | if(ClipboardJS.isSupported()) {
80 | $(document).ready(function() {
81 | var copyButton = "";
82 |
83 | $(".examples, div.sourceCode").addClass("hasCopyButton");
84 |
85 | // Insert copy buttons:
86 | $(copyButton).prependTo(".hasCopyButton");
87 |
88 | // Initialize tooltips:
89 | $('.btn-copy-ex').tooltip({container: 'body'});
90 |
91 | // Initialize clipboard:
92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', {
93 | text: function(trigger) {
94 | return trigger.parentNode.textContent;
95 | }
96 | });
97 |
98 | clipboardBtnCopies.on('success', function(e) {
99 | changeTooltipMessage(e.trigger, 'Copied!');
100 | e.clearSelection();
101 | });
102 |
103 | clipboardBtnCopies.on('error', function() {
104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy');
105 | });
106 | });
107 | }
108 | })(window.jQuery || window.$)
109 |
--------------------------------------------------------------------------------