R/read_scenario_data.R

Defines functions read_scenario_data

Documented in read_scenario_data

#' Read in scenario data
#'
#' Function reads in scenario data and checks for existence of required columns.
#'
#' @param path Path to dir holding scenario data.
#'
#' @return A tibble holding scenario data.
read_scenario_data <- function(path) {
  scenario_data <- validate_file_exists(path) %>%
    readr::read_csv(
      col_types = readr::cols(
        scenario_geography = "c",
        scenario = "c",
        scenario_type = "c",
        ald_sector = "c",
        units = "c",
        ald_business_unit = "c",
        year = "d",
        direction = "c",
        fair_share_perc = "d"
      )
    )

  validate_data_has_expected_cols(
    data = scenario_data,
    expected_columns = c(
      "scenario_geography", "scenario", "scenario_type",
      "ald_sector", "units", "ald_business_unit", "year",
      "direction", "fair_share_perc"
    )
  )

  return(scenario_data)
}
2DegreesInvesting/r2dii.climate.stress.test documentation built on June 6, 2024, 8:23 a.m.