R/lords_amendments.R

Defines functions lords_amendments

Documented in lords_amendments

#' House of Lords Amendments.
#'
#' Returns a tibble with all available House of Lords amendments, subject
#' to parameters.
#'
#' @param decision The decision on the amendments. Accepts one of
#' `'Withdrawn'`, `'Agreed'`, `'Disagreed'`, `'Pending'`,
#' `'NotMoved'`, `'Disposed'`. This parameter is not case sensitive.
#' Defaults to `NULL`.
#'
#' @param start_date Only includes amendments to bills introduced on or after
#' this date. Accepts character values in `'YYYY-MM-DD'` format, and
#' objects of class `Date`, `POSIXt`, `POSIXct`, `POSIXlt`
#' or anything else that can be coerced to a date with `as.Date()`.
#' Defaults to `'1900-01-01'`.
#'
#' @param end_date Only includes amendments to bills introduced on or before
#' this date. Accepts character values in `'YYYY-MM-DD'` format, and
#' objects of class `Date`, `POSIXt`, `POSIXct`, `POSIXlt`
#' or anything else that can be coerced to a date with `as.Date()`.
#' Defaults to the current system date.
#' @inheritParams all_answered_questions
#' @return A tibble with details on amendments proposed by the House of Lords.
#'
#' @export
#' @examples
#' \dontrun{
#' x <- lords_amendments()
#'
#' x <- lords_amendments(decision = "Withdrawn")
#' }
#'
lords_amendments <- function(decision = NULL, start_date = "1900-01-01",
                             end_date = Sys.Date(), extra_args = NULL,
                             tidy = TRUE, tidy_style = "snake",
                             verbose = TRUE) {
  dates <- paste0(
    "&min-bill.date=", as.Date(start_date),
    "&max-bill.date=", as.Date(end_date)
  )

  if (!is.null(decision)) {
    decision_query <- paste0("&decision=", gsub(
      "\\b([[:lower:]])([[:lower:]]+)", "\\U\\1\\L\\2",
      tolower(decision),
      perl = TRUE
    ))
  } else {
    decision_query <- ""
  }

  query <- paste0(
    url_util, "lordsbillamendments.json?",
    decision_query, dates, extra_args
  )

  df <- loop_query(query, verbose) # in utils-loop.R

  if (nrow(df) == 0) {
    message("The request did not return any data.
                Please check your parameters.")
  } else {
    if (tidy) {
      df <- lords_amendments_tidy(df, tidy_style)
    }

    df
  }
}


#' @rdname lords_amendments
#' @export
hansard_lords_amendments <- lords_amendments
evanodell/hansard documentation built on Oct. 10, 2021, 9:52 a.m.