diff --git a/R/fake_abcd_scenario_bonds.R b/R/fake_abcd_scenario_bonds.R new file mode 100644 index 0000000..402cdde --- /dev/null +++ b/R/fake_abcd_scenario_bonds.R @@ -0,0 +1,84 @@ +#' Create an example `abcd_scenario_bonds` object +#' +#' This function creates an example `abcd_scenario_bonds` object. +#' +#' @param scenario_source value/s to be used for the `scenario_source` column +#' @param scenario value/s to be used for the `scenario` column +#' @param id_name value/s to be used for the `id_name` column +#' @param id value/s to be used for the `id` column +#' @param ald_company_sector_id value/s to be used for the +#' `ald_company_sector_id` column +#' @param equity_market value/s to be used for the `equity_market` column +#' @param scenario_geography value/s to be used for the `scenario_geography` +#' column +#' @param ald_sector value/s to be used for the `ald_sector` column +#' @param technology value/s to be used for the `technology` column +#' @param year value/s to be used for the `year` column +#' @param plan_tech_prod value/s to be used for the `plan_tech_prod` column +#' @param plan_br_wt_factor value/s to be used for the `plan_br_wt_factor` +#' column +#' @param plan_br_wt_techshare value/s to be used for the `plan_br_wt_techshare` +#' column +#' @param plan_emission_factor value/s to be used for the `plan_emission_factor` +#' column +#' @param scen_tech_prod value/s to be used for the `scen_tech_prod` column +#' @param scen_br_wt_factor value/s to be used for the `scen_br_wt_factor` +#' column +#' @param scen_br_wt_techshare value/s to be used for the `scen_br_wt_techshare` +#' column +#' @param scen_emission_factor value/s to be used for the `scen_emission_factor` +#' column +#' @param current_plan_row value/s to be used for the `current_plan_row` column +#' @param scenario_exists value/s to be used for the `scenario_exists` column +#' +#' @return A data frame with the specified columns and/or their default values +#' +#' @export + +fake_abcd_scenario_bonds <- + function(scenario_source = "ISF2021", + scenario = "NZE", + id_name = "ar_company_id", + id = "10015", + ald_company_sector_id = "4", + equity_market = "DevelopedMarket", + scenario_geography = "Global", + ald_sector = "Coal", + technology = "Coal", + year = 2021, + plan_tech_prod = 0, + plan_br_wt_factor = NA_real_, + plan_br_wt_techshare = NA_real_, + plan_emission_factor = NA_real_, + scen_tech_prod = 0, + scen_br_wt_factor = NA_real_, + scen_br_wt_techshare = NA_real_, + scen_emission_factor = 0, + current_plan_row = 1, + scenario_exists = 1) { + `class<-`( + data.frame( + scenario_source = scenario_source, + scenario = scenario, + id_name = id_name, + id = id, + ald_company_sector_id = ald_company_sector_id, + equity_market = equity_market, + scenario_geography = scenario_geography, + ald_sector = ald_sector, + technology = technology, + year = year, + plan_tech_prod = plan_tech_prod, + plan_br_wt_factor = plan_br_wt_factor, + plan_br_wt_techshare = plan_br_wt_techshare, + plan_emission_factor = plan_emission_factor, + scen_tech_prod = scen_tech_prod, + scen_br_wt_factor = scen_br_wt_factor, + scen_br_wt_techshare = scen_br_wt_techshare, + scen_emission_factor = scen_emission_factor, + current_plan_row = current_plan_row, + scenario_exists = scenario_exists + ), + c("tbl", "data.frame") + ) + } diff --git a/R/fake_abcd_scenario_equity.R b/R/fake_abcd_scenario_equity.R new file mode 100644 index 0000000..5e5348d --- /dev/null +++ b/R/fake_abcd_scenario_equity.R @@ -0,0 +1,84 @@ +#' Create an example `abcd_scenario_equity` object +#' +#' This function creates an example `abcd_scenario_equity` object. +#' +#' @param scenario_source value/s to be used for the `scenario_source` column +#' @param scenario value/s to be used for the `scenario` column +#' @param id_name value/s to be used for the `id_name` column +#' @param id value/s to be used for the `id` column +#' @param ald_company_sector_id value/s to be used for the +#' `ald_company_sector_id` column +#' @param equity_market value/s to be used for the `equity_market` column +#' @param scenario_geography value/s to be used for the `scenario_geography` +#' column +#' @param ald_sector value/s to be used for the `ald_sector` column +#' @param technology value/s to be used for the `technology` column +#' @param year value/s to be used for the `year` column +#' @param plan_tech_prod value/s to be used for the `plan_tech_prod` column +#' @param plan_br_wt_factor value/s to be used for the `plan_br_wt_factor` +#' column +#' @param plan_br_wt_techshare value/s to be used for the `plan_br_wt_techshare` +#' column +#' @param plan_emission_factor value/s to be used for the `plan_emission_factor` +#' column +#' @param scen_tech_prod value/s to be used for the `scen_tech_prod` column +#' @param scen_br_wt_factor value/s to be used for the `scen_br_wt_factor` +#' column +#' @param scen_br_wt_techshare value/s to be used for the `scen_br_wt_techshare` +#' column +#' @param scen_emission_factor value/s to be used for the `scen_emission_factor` +#' column +#' @param current_plan_row value/s to be used for the `current_plan_row` column +#' @param scenario_exists value/s to be used for the `scenario_exists` column +#' +#' @return A data frame with the specified columns and/or their default values +#' +#' @export + +fake_abcd_scenario_equity <- + function(scenario_source = "ISF2021", + scenario = "NZE", + id_name = "ar_company_id", + id = "10015", + ald_company_sector_id = "4", + equity_market = "DevelopedMarket", + scenario_geography = "Global", + ald_sector = "Coal", + technology = "Coal", + year = 2021, + plan_tech_prod = 0, + plan_br_wt_factor = NA_real_, + plan_br_wt_techshare = NA_real_, + plan_emission_factor = NA_real_, + scen_tech_prod = 0, + scen_br_wt_factor = NA_real_, + scen_br_wt_techshare = NA_real_, + scen_emission_factor = 0, + current_plan_row = 1, + scenario_exists = 1) { + `class<-`( + data.frame( + scenario_source = scenario_source, + scenario = scenario, + id_name = id_name, + id = id, + ald_company_sector_id = ald_company_sector_id, + equity_market = equity_market, + scenario_geography = scenario_geography, + ald_sector = ald_sector, + technology = technology, + year = year, + plan_tech_prod = plan_tech_prod, + plan_br_wt_factor = plan_br_wt_factor, + plan_br_wt_techshare = plan_br_wt_techshare, + plan_emission_factor = plan_emission_factor, + scen_tech_prod = scen_tech_prod, + scen_br_wt_factor = scen_br_wt_factor, + scen_br_wt_techshare = scen_br_wt_techshare, + scen_emission_factor = scen_emission_factor, + current_plan_row = current_plan_row, + scenario_exists = scenario_exists + ), + c("tbl", "data.frame") + ) + } diff --git a/R/validate_abcd_scenario_bonds.R b/R/validate_abcd_scenario_bonds.R new file mode 100644 index 0000000..c944418 --- /dev/null +++ b/R/validate_abcd_scenario_bonds.R @@ -0,0 +1,170 @@ +#' Validate a `abcd_scenario_bonds` object +#' +#' This function validates that an object is a valid `abcd_scenario_bonds` dataset. +#' +#' @param data An object (typically a data frame) +#' +#' @return `TRUE` if the object is valid, otherwise an error with a message +#' explaining the failed assertions +#' +#' @export + +validate_abcd_scenario_bonds <- + function(data) { + coll <- checkmate::makeAssertCollection() + + checkmate::assert_data_frame(data, add = coll) + + if (checkmate::test_data_frame(data)) { + checkmate::assert_false(dplyr::is_grouped_df(data), add = coll) + + assert_columns_exists( + data, + col_names = c( + "scenario_source", + "scenario", + "id_name", + "id", + "ald_company_sector_id", + "equity_market", + "scenario_geography", + "ald_sector", + "technology", + "year", + "plan_tech_prod", + "plan_br_wt_factor", + "plan_br_wt_techshare", + "plan_emission_factor", + "scen_tech_prod", + "scen_br_wt_factor", + "scen_br_wt_techshare", + "scen_emission_factor", + "current_plan_row", + "scenario_exists"), + add = coll + ) + + # `scenario_source` column + col_name <- "scenario_source" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_character(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scenario` column + col_name <- "scenario" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_character(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `id_name` column + col_name <- "id_name" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_character(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `id` column + col_name <- "id" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_ai_company_id(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `ald_company_sector_id` column + col_name <- "ald_company_sector_id" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_character(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `equity_market` column + col_name <- "equity_market" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_equity_market(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scenario_geography` column + col_name <- "scenario_geography" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_scenario_geography(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `ald_sector` column + col_name <- "ald_sector" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_sector(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `technology` column + col_name <- "technology" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_technology(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + assert_valid_technology_for_sector(data[[col_name]], data[["ald_sector"]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `year` column + col_name <- "year" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_integerish(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `plan_tech_prod` column + col_name <- "plan_tech_prod" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `plan_br_wt_factor` column + col_name <- "plan_br_wt_factor" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `plan_br_wt_techshare` column + col_name <- "plan_br_wt_techshare" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `plan_emission_factor` column + col_name <- "plan_emission_factor" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scen_tech_prod` column + col_name <- "scen_tech_prod" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scen_br_wt_factor` column + col_name <- "scen_br_wt_factor" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scen_br_wt_techshare` column + col_name <- "scen_br_wt_techshare" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scen_emission_factor` column + col_name <- "scen_emission_factor" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `current_plan_row` column + col_name <- "current_plan_row" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_integerish(data[[col_name]], lower = 0, any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scenario_exists` column + col_name <- "scenario_exists" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_integerish(data[[col_name]], lower = 0, upper = 1, any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + } + + checkmate::reportAssertions(coll) + } diff --git a/R/validate_abcd_scenario_equity.R b/R/validate_abcd_scenario_equity.R new file mode 100644 index 0000000..a188c3b --- /dev/null +++ b/R/validate_abcd_scenario_equity.R @@ -0,0 +1,170 @@ +#' Validate a `abcd_scenario_equity` object +#' +#' This function validates that an object is a valid `abcd_scenario_equity` dataset. +#' +#' @param data An object (typically a data frame) +#' +#' @return `TRUE` if the object is valid, otherwise an error with a message +#' explaining the failed assertions +#' +#' @export + +validate_abcd_scenario_equity <- + function(data) { + coll <- checkmate::makeAssertCollection() + + checkmate::assert_data_frame(data, add = coll) + + if (checkmate::test_data_frame(data)) { + checkmate::assert_false(dplyr::is_grouped_df(data), add = coll) + + assert_columns_exists( + data, + col_names = c( + "scenario_source", + "scenario", + "id_name", + "id", + "ald_company_sector_id", + "equity_market", + "scenario_geography", + "ald_sector", + "technology", + "year", + "plan_tech_prod", + "plan_br_wt_factor", + "plan_br_wt_techshare", + "plan_emission_factor", + "scen_tech_prod", + "scen_br_wt_factor", + "scen_br_wt_techshare", + "scen_emission_factor", + "current_plan_row", + "scenario_exists"), + add = coll + ) + + # `scenario_source` column + col_name <- "scenario_source" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_character(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scenario` column + col_name <- "scenario" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_character(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `id_name` column + col_name <- "id_name" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_character(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `id` column + col_name <- "id" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_ai_company_id(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `ald_company_sector_id` column + col_name <- "ald_company_sector_id" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_character(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `equity_market` column + col_name <- "equity_market" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_equity_market(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scenario_geography` column + col_name <- "scenario_geography" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_scenario_geography(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `ald_sector` column + col_name <- "ald_sector" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_sector(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `technology` column + col_name <- "technology" + if (checkmate::test_names(names(data), must.include = col_name)) { + assert_valid_technology(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + assert_valid_technology_for_sector(data[[col_name]], data[["ald_sector"]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `year` column + col_name <- "year" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_integerish(data[[col_name]], any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `plan_tech_prod` column + col_name <- "plan_tech_prod" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `plan_br_wt_factor` column + col_name <- "plan_br_wt_factor" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `plan_br_wt_techshare` column + col_name <- "plan_br_wt_techshare" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `plan_emission_factor` column + col_name <- "plan_emission_factor" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scen_tech_prod` column + col_name <- "scen_tech_prod" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scen_br_wt_factor` column + col_name <- "scen_br_wt_factor" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scen_br_wt_techshare` column + col_name <- "scen_br_wt_techshare" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scen_emission_factor` column + col_name <- "scen_emission_factor" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_double(data[[col_name]], lower = 0, any.missing = TRUE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `current_plan_row` column + col_name <- "current_plan_row" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_integerish(data[[col_name]], lower = 0, any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + + # `scenario_exists` column + col_name <- "scenario_exists" + if (checkmate::test_names(names(data), must.include = col_name)) { + checkmate::assert_integerish(data[[col_name]], lower = 0, upper = 1, any.missing = FALSE, add = coll, .var.name = paste0("data$", col_name)) + } + } + + checkmate::reportAssertions(coll) + } diff --git a/man/fake_abcd_scenario_bonds.Rd b/man/fake_abcd_scenario_bonds.Rd new file mode 100644 index 0000000..0b5fd24 --- /dev/null +++ b/man/fake_abcd_scenario_bonds.Rd @@ -0,0 +1,84 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fake_abcd_scenario_bonds.R +\name{fake_abcd_scenario_bonds} +\alias{fake_abcd_scenario_bonds} +\title{Create an example \code{abcd_scenario_bonds} object} +\usage{ +fake_abcd_scenario_bonds( + scenario_source = "ISF2021", + scenario = "NZE", + id_name = "ar_company_id", + id = "10015", + ald_company_sector_id = "4", + equity_market = "DevelopedMarket", + scenario_geography = "Global", + ald_sector = "Coal", + technology = "Coal", + year = 2021, + plan_tech_prod = 0, + plan_br_wt_factor = NA_real_, + plan_br_wt_techshare = NA_real_, + plan_emission_factor = NA_real_, + scen_tech_prod = 0, + scen_br_wt_factor = NA_real_, + scen_br_wt_techshare = NA_real_, + scen_emission_factor = 0, + current_plan_row = 1, + scenario_exists = 1 +) +} +\arguments{ +\item{scenario_source}{value/s to be used for the \code{scenario_source} column} + +\item{scenario}{value/s to be used for the \code{scenario} column} + +\item{id_name}{value/s to be used for the \code{id_name} column} + +\item{id}{value/s to be used for the \code{id} column} + +\item{ald_company_sector_id}{value/s to be used for the +\code{ald_company_sector_id} column} + +\item{equity_market}{value/s to be used for the \code{equity_market} column} + +\item{scenario_geography}{value/s to be used for the \code{scenario_geography} +column} + +\item{ald_sector}{value/s to be used for the \code{ald_sector} column} + +\item{technology}{value/s to be used for the \code{technology} column} + +\item{year}{value/s to be used for the \code{year} column} + +\item{plan_tech_prod}{value/s to be used for the \code{plan_tech_prod} column} + +\item{plan_br_wt_factor}{value/s to be used for the \code{plan_br_wt_factor} +column} + +\item{plan_br_wt_techshare}{value/s to be used for the \code{plan_br_wt_techshare} +column} + +\item{plan_emission_factor}{value/s to be used for the \code{plan_emission_factor} +column} + +\item{scen_tech_prod}{value/s to be used for the \code{scen_tech_prod} column} + +\item{scen_br_wt_factor}{value/s to be used for the \code{scen_br_wt_factor} +column} + +\item{scen_br_wt_techshare}{value/s to be used for the \code{scen_br_wt_techshare} +column} + +\item{scen_emission_factor}{value/s to be used for the \code{scen_emission_factor} +column} + +\item{current_plan_row}{value/s to be used for the \code{current_plan_row} column} + +\item{scenario_exists}{value/s to be used for the \code{scenario_exists} column} +} +\value{ +A data frame with the specified columns and/or their default values +} +\description{ +This function creates an example \code{abcd_scenario_bonds} object. +} diff --git a/man/fake_abcd_scenario_equity.Rd b/man/fake_abcd_scenario_equity.Rd new file mode 100644 index 0000000..9cbb64c --- /dev/null +++ b/man/fake_abcd_scenario_equity.Rd @@ -0,0 +1,84 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fake_abcd_scenario_equity.R +\name{fake_abcd_scenario_equity} +\alias{fake_abcd_scenario_equity} +\title{Create an example \code{abcd_scenario_equity} object} +\usage{ +fake_abcd_scenario_equity( + scenario_source = "ISF2021", + scenario = "NZE", + id_name = "ar_company_id", + id = "10015", + ald_company_sector_id = "4", + equity_market = "DevelopedMarket", + scenario_geography = "Global", + ald_sector = "Coal", + technology = "Coal", + year = 2021, + plan_tech_prod = 0, + plan_br_wt_factor = NA_real_, + plan_br_wt_techshare = NA_real_, + plan_emission_factor = NA_real_, + scen_tech_prod = 0, + scen_br_wt_factor = NA_real_, + scen_br_wt_techshare = NA_real_, + scen_emission_factor = 0, + current_plan_row = 1, + scenario_exists = 1 +) +} +\arguments{ +\item{scenario_source}{value/s to be used for the \code{scenario_source} column} + +\item{scenario}{value/s to be used for the \code{scenario} column} + +\item{id_name}{value/s to be used for the \code{id_name} column} + +\item{id}{value/s to be used for the \code{id} column} + +\item{ald_company_sector_id}{value/s to be used for the +\code{ald_company_sector_id} column} + +\item{equity_market}{value/s to be used for the \code{equity_market} column} + +\item{scenario_geography}{value/s to be used for the \code{scenario_geography} +column} + +\item{ald_sector}{value/s to be used for the \code{ald_sector} column} + +\item{technology}{value/s to be used for the \code{technology} column} + +\item{year}{value/s to be used for the \code{year} column} + +\item{plan_tech_prod}{value/s to be used for the \code{plan_tech_prod} column} + +\item{plan_br_wt_factor}{value/s to be used for the \code{plan_br_wt_factor} +column} + +\item{plan_br_wt_techshare}{value/s to be used for the \code{plan_br_wt_techshare} +column} + +\item{plan_emission_factor}{value/s to be used for the \code{plan_emission_factor} +column} + +\item{scen_tech_prod}{value/s to be used for the \code{scen_tech_prod} column} + +\item{scen_br_wt_factor}{value/s to be used for the \code{scen_br_wt_factor} +column} + +\item{scen_br_wt_techshare}{value/s to be used for the \code{scen_br_wt_techshare} +column} + +\item{scen_emission_factor}{value/s to be used for the \code{scen_emission_factor} +column} + +\item{current_plan_row}{value/s to be used for the \code{current_plan_row} column} + +\item{scenario_exists}{value/s to be used for the \code{scenario_exists} column} +} +\value{ +A data frame with the specified columns and/or their default values +} +\description{ +This function creates an example \code{abcd_scenario_equity} object. +} diff --git a/man/validate_abcd_scenario_bonds.Rd b/man/validate_abcd_scenario_bonds.Rd new file mode 100644 index 0000000..a018d31 --- /dev/null +++ b/man/validate_abcd_scenario_bonds.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/validate_abcd_scenario_bonds.R +\name{validate_abcd_scenario_bonds} +\alias{validate_abcd_scenario_bonds} +\title{Validate a \code{abcd_scenario_bonds} object} +\usage{ +validate_abcd_scenario_bonds(data) +} +\arguments{ +\item{data}{An object (typically a data frame)} +} +\value{ +\code{TRUE} if the object is valid, otherwise an error with a message +explaining the failed assertions +} +\description{ +This function validates that an object is a valid \code{abcd_scenario_bonds} dataset. +} diff --git a/man/validate_abcd_scenario_equity.Rd b/man/validate_abcd_scenario_equity.Rd new file mode 100644 index 0000000..606c49e --- /dev/null +++ b/man/validate_abcd_scenario_equity.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/validate_abcd_scenario_equity.R +\name{validate_abcd_scenario_equity} +\alias{validate_abcd_scenario_equity} +\title{Validate a \code{abcd_scenario_equity} object} +\usage{ +validate_abcd_scenario_equity(data) +} +\arguments{ +\item{data}{An object (typically a data frame)} +} +\value{ +\code{TRUE} if the object is valid, otherwise an error with a message +explaining the failed assertions +} +\description{ +This function validates that an object is a valid \code{abcd_scenario_equity} dataset. +} diff --git a/tests/testthat/test-fake_abcd_scenario_bonds.R b/tests/testthat/test-fake_abcd_scenario_bonds.R new file mode 100644 index 0000000..18cc6dc --- /dev/null +++ b/tests/testthat/test-fake_abcd_scenario_bonds.R @@ -0,0 +1,3 @@ +test_that("returns a valid `abcd_scenario_bonds` obj", { + expect_no_error(validate_abcd_scenario_bonds(fake_abcd_scenario_bonds())) +}) diff --git a/tests/testthat/test-fake_abcd_scenario_equity.R b/tests/testthat/test-fake_abcd_scenario_equity.R new file mode 100644 index 0000000..f4f97fc --- /dev/null +++ b/tests/testthat/test-fake_abcd_scenario_equity.R @@ -0,0 +1,3 @@ +test_that("returns a valid `abcd_scenario_equity` obj", { + expect_no_error(validate_abcd_scenario_equity(fake_abcd_scenario_equity())) +}) diff --git a/tests/testthat/test-validate_abcd_scenario_bonds.R b/tests/testthat/test-validate_abcd_scenario_bonds.R new file mode 100644 index 0000000..e758ed3 --- /dev/null +++ b/tests/testthat/test-validate_abcd_scenario_bonds.R @@ -0,0 +1,192 @@ +test_that("errors if not a data frame", { + msg <- "Must be of type 'data.frame'" + expect_error(validate_abcd_scenario_bonds("a"), regexp = msg) + expect_error(validate_abcd_scenario_bonds(1), regexp = msg) + expect_error(validate_abcd_scenario_bonds(list(1)), regexp = msg) +}) + +test_that("errors if columns are missing", { + data <- fake_abcd_scenario_bonds() + data$scenario_source <- NULL + msg <- 'column "scenario_source" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$scenario <- NULL + msg <- 'column "scenario" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$id_name <- NULL + msg <- 'column "id_name" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$id <- NULL + msg <- 'column "id" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$ald_company_sector_id <- NULL + msg <- 'column "ald_company_sector_id" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$equity_market <- NULL + msg <- 'column "equity_market" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$scenario_geography <- NULL + msg <- 'column "scenario_geography" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$ald_sector <- NULL + msg <- 'column "ald_sector" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$technology <- NULL + msg <- 'column "technology" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$year <- NULL + msg <- 'column "year" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$plan_tech_prod <- NULL + msg <- 'column "plan_tech_prod" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$plan_br_wt_factor <- NULL + msg <- 'column "plan_br_wt_factor" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$plan_br_wt_techshare <- NULL + msg <- 'column "plan_br_wt_techshare" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$plan_emission_factor <- NULL + msg <- 'column "plan_emission_factor" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$scen_tech_prod <- NULL + msg <- 'column "scen_tech_prod" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$scen_br_wt_factor <- NULL + msg <- 'column "scen_br_wt_factor" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$scen_br_wt_techshare <- NULL + msg <- 'column "scen_br_wt_techshare" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$scen_emission_factor <- NULL + msg <- 'column "scen_emission_factor" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$current_plan_row <- NULL + msg <- 'column "current_plan_row" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds() + data$scenario_exists <- NULL + msg <- 'column "scenario_exists" must exist.' + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) +}) + +test_that("errors if `scenario_source` contains invalid data", { + msg <- "Must be of type 'character'" + + data <- fake_abcd_scenario_bonds(scenario_source = 8) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds(scenario_source = TRUE) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + msg <- "Contains missing values" + data <- fake_abcd_scenario_bonds(scenario_source = NA_character_) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) +}) + +test_that("errors if `scenario` contains invalid data", { + msg <- "Must be of type 'character'" + + data <- fake_abcd_scenario_bonds(scenario = 8) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds(scenario = TRUE) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + msg <- "Contains missing values" + data <- fake_abcd_scenario_bonds(scenario = NA_character_) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) +}) + +test_that("errors if `id_name` contains invalid data", { + msg <- "Must be of type 'character'" + + data <- fake_abcd_scenario_bonds(id_name = 8) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds(id_name = TRUE) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + msg <- "Contains missing values" + data <- fake_abcd_scenario_bonds(id_name = NA_character_) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) +}) + +test_that("errors if `id` contains invalid data", { + msg <- "must be a character vector" + + data <- fake_abcd_scenario_bonds(id = 8) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds(id = TRUE) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + msg <- "must contain only valid AI company IDs" + data <- fake_abcd_scenario_bonds(id = NA_character_) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) +}) + +test_that("errors if `ald_company_sector_id` contains invalid data", { + msg <- "Must be of type 'character'" + + data <- fake_abcd_scenario_bonds(ald_company_sector_id = 8) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds(ald_company_sector_id = TRUE) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + msg <- "Contains missing values" + data <- fake_abcd_scenario_bonds(ald_company_sector_id = NA_character_) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) +}) + +test_that("errors if `equity_market` contains invalid data", { + msg <- "valid equity market" + + data <- fake_abcd_scenario_bonds(equity_market = 8) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + data <- fake_abcd_scenario_bonds(equity_market = TRUE) + expect_error(validate_abcd_scenario_bonds(data), regexp = msg) + + # msg <- "Contains missing values" + # data <- fake_abcd_scenario_bonds(equity_market = NA_character_) + # expect_error(validate_abcd_scenario_bonds(data), regexp = msg) +})