R/load_pf_core.R

Defines functions load_pf_core

Documented in load_pf_core

#' Helper to load core PartyFacts data
#'
#' @description This function allows to conveniently load PartyFacts data and subset the countries of interest.
#'
#' @param countries A character vector of VDEM country codes.
#'
#' @return A tibble with PartyFacts data for the countries of interest.
#' @export load_pf_core
#'
#' @examples
#'
#' library(partymakeR)
#'
#' \dontrun{
#'
#' # Define countries of interest
#' countries <- c("AFG", "AIA")
#'
#' # Load data
#' dat_pf_core <- load_pf_core(countries = countries)
#'
#' }
#'
load_pf_core <- function(countries = NULL) {

  if (is.null(countries)) {

    readr::read_csv(here::here("data_input", "partyfacts",
                               "partyfacts-core-parties.csv"),
                    show_col_types = FALSE)

  } else if (is.character(countries)) {

    dat <- readr::read_csv(here::here("data_input", "partyfacts",
                                      "partyfacts-core-parties.csv"),
                           show_col_types = FALSE)
    dat[dat$country %in% countries, ]

  }

}
RobertoValli/partymakeR documentation built on June 15, 2022, 2:12 p.m.