From 94d302ef1f16f4fe6d11774b098b91b7dcecebf1 Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Thu, 14 Mar 2024 14:16:32 +0100 Subject: [PATCH] upkeep: complete deprecation of `ald` in favour of `abcd` (#479) --- NAMESPACE | 1 - NEWS.md | 2 + R/join_abcd_scenario.R | 1 - R/join_ald_scenario.R | 64 ----- R/summarize_weighted_production.R | 8 - R/target_market_share.R | 16 +- R/target_sda.R | 16 +- R/utils.R | 52 ---- inst/WORDLIST | 2 - man/join_ald_scenario.Rd | 52 ---- man/target_market_share.Rd | 6 +- man/target_sda.Rd | 6 +- tests/testthat/_snaps/join_ald_scenario.md | 16 -- tests/testthat/helper-fake_data.R | 24 -- tests/testthat/test-join_ald_scenario.R | 272 --------------------- 15 files changed, 6 insertions(+), 532 deletions(-) delete mode 100644 R/join_ald_scenario.R delete mode 100644 man/join_ald_scenario.Rd delete mode 100644 tests/testthat/_snaps/join_ald_scenario.md delete mode 100644 tests/testthat/test-join_ald_scenario.R diff --git a/NAMESPACE b/NAMESPACE index 72b895e9..75d43577 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,7 +9,6 @@ export(enquo) export(enquos) export(expr) export(join_abcd_scenario) -export(join_ald_scenario) export(summarize_weighted_percent_change) export(summarize_weighted_production) export(sym) diff --git a/NEWS.md b/NEWS.md index 570f1eaf..61d27e9d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # r2dii.analysis (development version) +* Completed deprecation of `ald` in favour of `abcd` (#466). + * `target_market_share` now correctly handles input scenarios with a hyphen in their name (#425). * `target_market_share` now handles `abcd` with rows where `production` is `NA` by filling with `0` (#423). diff --git a/R/join_abcd_scenario.R b/R/join_abcd_scenario.R index 68335f1c..3af8f89c 100644 --- a/R/join_abcd_scenario.R +++ b/R/join_abcd_scenario.R @@ -39,7 +39,6 @@ join_abcd_scenario <- function(data, scenario, region_isos = r2dii.data::region_isos, add_green_technologies = FALSE) { - data <- rename_and_warn_ald_names(data) check_portfolio_abcd_scenario(data, abcd, scenario) diff --git a/R/join_ald_scenario.R b/R/join_ald_scenario.R deleted file mode 100644 index 0cd1943f..00000000 --- a/R/join_ald_scenario.R +++ /dev/null @@ -1,64 +0,0 @@ -#' Join a data-loanbook object to the ald and scenario -#' -#' @description -#' `r lifecycle::badge("deprecated")` -#' -#' This function was deprecated in favour of [join_abcd_scenario()]. See [here](https://2degreesinvesting.github.io/posts/2022-03-02-ald-becomes-abcd/) -#' for more information. -#' -#' @keywords internal -#' -#' @export -#' -#' @examples -#' \dontrun{ -#' installed <- requireNamespace("r2dii.data", quietly = TRUE) && -#' requireNamespace("r2dii.match", quietly = TRUE) && -#' packageVersion("r2dii.match") >= "0.1.0" -#' -#' if (installed) { -#' library(r2dii.data) -#' library(r2dii.match) -#' -#' valid_matches <- match_name(loanbook_demo, ald_demo) %>% -#' prioritize() -#' -#' valid_matches %>% -#' join_ald_scenario( -#' ald = ald_demo, -#' scenario = scenario_demo_2020, -#' region_isos = region_isos_demo -#' ) -#' -#' # -> -#' -#' valid_matches %>% -#' join_abcd_scenario( -#' abcd = abcd_demo, -#' scenario = scenario_demo_2020, -#' region_isos = region_isos_demo -#' ) -#' } -#' } -join_ald_scenario <- function(data, - ald, - scenario, - region_isos = r2dii.data::region_isos, - add_green_technologies = FALSE) { - lifecycle::deprecate_warn( - "0.2.0", - "join_ald_scenario()", - "join_abcd_scenario()" - ) - - if ("name_ald" %in% names(data)) { - data <- rename(data, name_abcd = "name_ald") - } - - if ("sector_ald" %in% names(data)) { - data <- rename(data, sector_abcd = "sector_ald") - } - - join_abcd_scenario(data, ald, scenario, region_isos, add_green_technologies) - -} diff --git a/R/summarize_weighted_production.R b/R/summarize_weighted_production.R index e4279748..04a17b89 100644 --- a/R/summarize_weighted_production.R +++ b/R/summarize_weighted_production.R @@ -58,8 +58,6 @@ summarize_weighted_production_ <- function(data, ..., use_credit_limit = FALSE, old_groups <- dplyr::groups(data) - data <- rename_and_warn_ald_names(data) - crucial <- c("production", "sector_abcd", "year", "technology") if (with_targets) { @@ -149,8 +147,6 @@ summarize_unweighted_production <- function(data, ..., with_targets = FALSE) { summarize_weighted_percent_change <- function(data, ..., use_credit_limit = FALSE) { stopifnot(is.data.frame(data)) - data <- rename_and_warn_ald_names(data) - data %>% ungroup() %>% add_loan_weight(use_credit_limit = use_credit_limit) %>% @@ -167,8 +163,6 @@ summarize_weighted_percent_change <- function(data, ..., use_credit_limit = FALS summarize_weighted_emission_factor <- function(data, ..., use_credit_limit = FALSE) { stopifnot(is.data.frame(data)) - data <- rename_and_warn_ald_names(data) - data %>% ungroup() %>% add_loan_weight(use_credit_limit = use_credit_limit) %>% @@ -182,8 +176,6 @@ summarize_weighted_emission_factor <- function(data, ..., use_credit_limit = FAL summarize_unweighted_emission_factor <- function(data, ...) { - data <- rename_and_warn_ald_names(data) - data <- data %>% select( -all_of(c("id_loan", "loan_size_credit_limit", "loan_size_outstanding")) diff --git a/R/target_market_share.R b/R/target_market_share.R index d253fba4..7645da91 100644 --- a/R/target_market_share.R +++ b/R/target_market_share.R @@ -21,8 +21,6 @@ #' output the unweighted production values. #' @param increasing_or_decreasing A data frame like #' [r2dii.data::increasing_or_decreasing]. -#' @param ald `r lifecycle::badge('superseded')` `ald` has been superseded by -#' `abcd`. #' #' @return A tibble including the summarized columns `metric`, `production`, #' `technology_share`, `percentage_of_initial_production_by_scope` and @@ -76,8 +74,7 @@ target_market_share <- function(data, use_credit_limit = FALSE, by_company = FALSE, weight_production = TRUE, - increasing_or_decreasing = r2dii.data::increasing_or_decreasing, - ald = deprecated()) { + increasing_or_decreasing = r2dii.data::increasing_or_decreasing) { stopifnot( is.data.frame(data), is.data.frame(abcd), @@ -88,17 +85,6 @@ target_market_share <- function(data, is.logical(weight_production) ) - if (lifecycle::is_present(ald)) { - lifecycle::deprecate_warn( - "0.2.0 (expected July 2022)", - "target_market_share(ald)", - "target_market_share(abcd)" - ) - abcd <- ald - } - - data <- rename_and_warn_ald_names(data) - abcd <- fill_and_warn_na(abcd, "production") region_isos <- change_to_lowercase_and_warn(region_isos, "isos") diff --git a/R/target_sda.R b/R/target_sda.R index b3f75d67..f405e02b 100644 --- a/R/target_sda.R +++ b/R/target_sda.R @@ -25,8 +25,6 @@ #' @return A tibble including the summarized columns `emission_factor_metric` and #' `emission_factor_value`. If `by_company = TRUE`, the output will also have #' the column `name_abcd`. -#' @param ald `r lifecycle::badge('superseded')` `ald` has been superseded by -#' `abcd`. #' #' @export #' @@ -65,8 +63,7 @@ target_sda <- function(data, co2_intensity_scenario, use_credit_limit = FALSE, by_company = FALSE, - region_isos = r2dii.data::region_isos, - ald = deprecated()) { + region_isos = r2dii.data::region_isos) { stopifnot( is.data.frame(data), is.data.frame(abcd), @@ -75,17 +72,6 @@ target_sda <- function(data, is.logical(by_company) ) - if (lifecycle::is_present(ald)) { - lifecycle::deprecate_warn( - "0.2.0 (expected July 2022)", - "target_market_share(ald)", - "target_market_share(abcd)" - ) - abcd <- ald - } - - data <- rename_and_warn_ald_names(data) - data <- ungroup(warn_grouped(data, "Ungrouping input data.")) crucial_portfolio <- c( diff --git a/R/utils.R b/R/utils.R index 35c4bf67..6fee5395 100644 --- a/R/utils.R +++ b/R/utils.R @@ -70,58 +70,6 @@ modify_at_ <- function(.x, .at, .f) { .x } -rename_and_warn_ald_names <- function(data) { - - if (all(c("name_ald", "name_abcd") %in% names(data))) { - - rlang::abort( - "too_many_sectors", - message = glue( - "Column `name_ald` is deprecated as of r2dii.match 0.1.0, please use - `name_abcd` instead." - ) - ) - - } else if ("name_ald" %in% names(data)) { - - rlang::warn( - "deprecated_name", - message = glue( - "Column `name_ald` is deprecated as of r2dii.match 0.1.0, please use - `name_abcd` instead." - ) - ) - - data <- dplyr::rename(data, name_abcd = "name_ald") - } - - if (all(c("sector_ald", "sector_abcd") %in% names(data))) { - - rlang::abort( - "too_many_sectors", - message = glue( - "Column `sector_ald` is deprecated as of r2dii.analysis 0.2.0, please use - `sector_abcd` instead." - ) - ) - - } else if ("sector_ald" %in% names(data)) { - - rlang::warn( - "deprecated_name", - message = glue( - "Column `sector_ald` is deprecated as of r2dii.analysis 0.2.0, please use - `sector_abcd` instead." - ) - ) - - data <- dplyr::rename(data, sector_abcd = "sector_ald") - } - - data - -} - change_to_lowercase_and_warn <- function(data, column) { if(any(data[[column]] != tolower(data[[column]]), na.rm = TRUE)) { name_dataset <- deparse(substitute(data)) diff --git a/inst/WORDLIST b/inst/WORDLIST index 3634767f..cbb7f431 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,4 +1,3 @@ -ALD BMU CDP CMD @@ -16,7 +15,6 @@ Sectoral WRI WWF abcd -ald decarbonization dev dfrac diff --git a/man/join_ald_scenario.Rd b/man/join_ald_scenario.Rd deleted file mode 100644 index 84ee153f..00000000 --- a/man/join_ald_scenario.Rd +++ /dev/null @@ -1,52 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/join_ald_scenario.R -\name{join_ald_scenario} -\alias{join_ald_scenario} -\title{Join a data-loanbook object to the ald and scenario} -\usage{ -join_ald_scenario( - data, - ald, - scenario, - region_isos = r2dii.data::region_isos, - add_green_technologies = FALSE -) -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} - -This function was deprecated in favour of \code{\link[=join_abcd_scenario]{join_abcd_scenario()}}. See \href{https://2degreesinvesting.github.io/posts/2022-03-02-ald-becomes-abcd/}{here} -for more information. -} -\examples{ -\dontrun{ -installed <- requireNamespace("r2dii.data", quietly = TRUE) && - requireNamespace("r2dii.match", quietly = TRUE) && - packageVersion("r2dii.match") >= "0.1.0" - -if (installed) { - library(r2dii.data) - library(r2dii.match) - - valid_matches <- match_name(loanbook_demo, ald_demo) \%>\% - prioritize() - - valid_matches \%>\% - join_ald_scenario( - ald = ald_demo, - scenario = scenario_demo_2020, - region_isos = region_isos_demo - ) - - # -> - - valid_matches \%>\% - join_abcd_scenario( - abcd = abcd_demo, - scenario = scenario_demo_2020, - region_isos = region_isos_demo - ) -} -} -} -\keyword{internal} diff --git a/man/target_market_share.Rd b/man/target_market_share.Rd index 0580aa07..73e4714a 100644 --- a/man/target_market_share.Rd +++ b/man/target_market_share.Rd @@ -12,8 +12,7 @@ target_market_share( use_credit_limit = FALSE, by_company = FALSE, weight_production = TRUE, - increasing_or_decreasing = r2dii.data::increasing_or_decreasing, - ald = deprecated() + increasing_or_decreasing = r2dii.data::increasing_or_decreasing ) } \arguments{ @@ -39,9 +38,6 @@ output the unweighted production values.} \item{increasing_or_decreasing}{A data frame like \link[r2dii.data:increasing_or_decreasing]{r2dii.data::increasing_or_decreasing}.} - -\item{ald}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} \code{ald} has been superseded by -\code{abcd}.} } \value{ A tibble including the summarized columns \code{metric}, \code{production}, diff --git a/man/target_sda.Rd b/man/target_sda.Rd index 25867d01..f806a059 100644 --- a/man/target_sda.Rd +++ b/man/target_sda.Rd @@ -11,8 +11,7 @@ target_sda( co2_intensity_scenario, use_credit_limit = FALSE, by_company = FALSE, - region_isos = r2dii.data::region_isos, - ald = deprecated() + region_isos = r2dii.data::region_isos ) } \arguments{ @@ -33,9 +32,6 @@ the column \code{loan_size_outstanding}. Set to \code{TRUE} to instead use the c \code{weighted_production_value} at the company-level.} \item{region_isos}{A data frame like \link[r2dii.data:region_isos]{r2dii.data::region_isos} (default).} - -\item{ald}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#superseded}{\figure{lifecycle-superseded.svg}{options: alt='[Superseded]'}}}{\strong{[Superseded]}} \code{ald} has been superseded by -\code{abcd}.} } \value{ A tibble including the summarized columns \code{emission_factor_metric} and diff --git a/tests/testthat/_snaps/join_ald_scenario.md b/tests/testthat/_snaps/join_ald_scenario.md deleted file mode 100644 index 2f41a763..00000000 --- a/tests/testthat/_snaps/join_ald_scenario.md +++ /dev/null @@ -1,16 +0,0 @@ -# with fake data outputs known value - - Code - out - Output - # A tibble: 1 x 22 - id_loan loan_size_outstanding loan_size_outstanding_c~1 loan_size_credit_limit - - 1 L162 1 EUR 2 - # i abbreviated name: 1: loan_size_outstanding_currency - # i 18 more variables: loan_size_credit_limit_currency , id_2dii , - # level , score , sector , name_abcd , sector_abcd , - # technology , year , production , emission_factor , - # plant_location , is_ultimate_owner , scenario , - # region , tmsr , smsp , scenario_source - diff --git a/tests/testthat/helper-fake_data.R b/tests/testthat/helper-fake_data.R index 4a875554..cbfac42f 100644 --- a/tests/testthat/helper-fake_data.R +++ b/tests/testthat/helper-fake_data.R @@ -59,30 +59,6 @@ fake_matched <- function(id_loan = NULL, ) } -#' See `fake_matched()` -#' @noRd -fake_ald <- function(name_company = NULL, - sector = NULL, - technology = NULL, - year = NULL, - production = NULL, - emission_factor = NULL, - plant_location = NULL, - is_ultimate_owner = NULL, - ...) { - tibble( - name_company = name_company %||% "shaanxi auto", - sector = sector %||% "automotive", - technology = technology %||% "ice", - year = year %||% 2025, - production = production %||% 1, - emission_factor = emission_factor %||% 1, - plant_location = plant_location %||% "BF", - is_ultimate_owner = is_ultimate_owner %||% TRUE, - ... - ) -} - #' See `fake_matched()` #' @noRd fake_abcd <- function(name_company = NULL, diff --git a/tests/testthat/test-join_ald_scenario.R b/tests/testthat/test-join_ald_scenario.R deleted file mode 100644 index 92db37ae..00000000 --- a/tests/testthat/test-join_ald_scenario.R +++ /dev/null @@ -1,272 +0,0 @@ -library(dplyr, warn.conflicts = FALSE) -library(r2dii.data) - -test_that("with fake data outputs known value", { - withr::local_options(lifecycle_verbosity = "quiet") - out <- join_ald_scenario( - fake_matched(), - ald = fake_abcd(), - scenario = fake_scenario(), - region_isos = region_isos_stable - ) - expect_snapshot(out) -}) - -test_that("returns visibly", { - withr::local_options(lifecycle_verbosity = "quiet") - expect_visible( - join_ald_scenario( - fake_matched(), - ald = fake_abcd(), - scenario = fake_scenario(), - region_isos = region_isos_stable - ) - ) -}) - -test_that("outputs expected names", { - withr::local_options(lifecycle_verbosity = "quiet") - expected <- setdiff( - c( - names(fake_matched()), - names(fake_abcd()), - names(fake_scenario()), - # Comes from region_isos which is used internally - "scenario_source" - ), - "name_company" - ) - - out <- join_ald_scenario( - fake_matched(), - ald = fake_abcd(), - scenario = fake_scenario(), - region_isos = region_isos_stable - ) - expect_equal( - sort(unique(names(out))), - sort(unique(expected)) - ) - - out2 <- join_ald_scenario( - fake_matched(new_column = "anything"), - ald = fake_abcd(), - scenario = fake_scenario(), - region_isos = region_isos_stable - ) - expect_equal( - sort(unique(c(names(out2)), "new_column")), - sort(unique(c(expected, "new_column"))) - ) -}) - -test_that("is sensitive to region_isos", { - withr::local_options(lifecycle_verbosity = "quiet") - out1 <- join_ald_scenario( - fake_matched(), - ald = fake_abcd(), - scenario = fake_scenario(scenario_source = "weo_2019"), - region_isos = r2dii.data::region_isos - ) - - out2 <- join_ald_scenario( - fake_matched(), - ald = fake_abcd(), - scenario = fake_scenario(scenario_source = "demo_2020"), - region_isos = region_isos_stable - ) - - expect_false(identical(out1, out2)) -}) - -test_that("is case-insensitive to `plant_location` inputs", { - withr::local_options(lifecycle_verbosity = "quiet") - lowercase <- "a" - out1 <- join_ald_scenario( - fake_matched(), - ald = fake_abcd(plant_location = lowercase), - scenario = fake_scenario(region = "b", scenario_source = "c"), - region_isos = tibble(isos = "a", region = "b", source = "c") - ) - - uppercase <- "A" - out2 <- join_ald_scenario( - fake_matched(), - ald = fake_abcd(plant_location = uppercase), - scenario = fake_scenario(region = "b", scenario_source = "c"), - region_isos = tibble(isos = "a", region = "b", source = "c") - ) - - expect_equal(out1, out2) -}) - -test_that("outputs a number of rows equal to matches by `scenario_source`", { - withr::local_options(lifecycle_verbosity = "quiet") - matching_0 <- suppressWarnings( - join_ald_scenario( - fake_matched(), - ald = fake_abcd(plant_location = "a"), - scenario = fake_scenario(region = "b", scenario_source = "c"), - region_isos = tibble(isos = "a", region = "b", source = "-") - ) - ) - expect_equal(nrow(matching_0), 0L) - - matching_1 <- join_ald_scenario( - fake_matched(), - ald = fake_abcd(plant_location = "a"), - scenario = fake_scenario(region = "b", scenario_source = "c"), - region_isos = tibble(isos = "a", region = "b", source = "c") - ) - expect_equal(nrow(matching_1), 1L) - - matching_2 <- join_ald_scenario( - fake_matched(), - ald = fake_abcd(plant_location = "a"), - scenario = fake_scenario(region = "b", scenario_source = c("c", "c")), - region_isos = tibble(isos = "a", region = "b", source = "c") - ) - expect_equal(nrow(matching_2), 2L) -}) - -test_that("w/ loanbook, ald or scenario with missing names errors gracefully", { - withr::local_options(lifecycle_verbosity = "quiet") - bad <- function(data, x) rename(data, bad = all_of(x)) - - expect_error_missing_names <- function(match_result = fake_matched(), - ald = fake_abcd(), - scenario = fake_scenario()) { - expect_error( - class = "missing_names", - join_ald_scenario(match_result, ald, scenario) - ) - } - - expect_error_missing_names(match_result = bad(fake_matched(), "name_abcd")) - expect_error_missing_names(match_result = bad(fake_matched(), "sector_abcd")) - - expect_error_missing_names(ald = bad(fake_abcd(), "name_company")) - expect_error_missing_names(ald = bad(fake_abcd(), "sector")) - expect_error_missing_names(ald = bad(fake_abcd(), "technology")) - expect_error_missing_names(ald = bad(fake_abcd(), "year")) - - expect_error_missing_names(scenario = bad(fake_scenario(), "sector")) - expect_error_missing_names(scenario = bad(fake_scenario(), "technology")) - expect_error_missing_names(scenario = bad(fake_scenario(), "year")) - - expect_error_missing_names(scenario = bad(fake_scenario(), "scenario_source")) -}) - -test_that("without `sector` throws no error", { - withr::local_options(lifecycle_verbosity = "quiet") - # RMI-PACTA/r2dii.analysis/pull/62#issuecomment-634651157 - without_sector <- select(fake_matched(), -sector) - expect_error_free( - join_ald_scenario( - without_sector, - ald = fake_abcd(), - scenario = fake_scenario(), - region_isos = region_isos_stable - ) - ) -}) - -test_that("warns 0-rows caused by scenario or region_isos", { - withr::local_options(lifecycle_verbosity = "quiet") - join_ald_scenario2 <- function(l, scenario = NULL, region_isos = NULL) { - scenario <- scenario %||% fake_scenario( - region = l$region, sector = l$sector, scenario_source = l$source - ) - region_isos <- region_isos %||% tibble( - region = l$region, isos = l$isos, source = l$source - ) - - join_ald_scenario( - fake_matched(sector_abcd = l$sector), - ald = fake_abcd(plant_location = l$isos, sector = l$sector), - scenario = scenario, - region_isos = region_isos - ) - } - - l <- list(sector = "a", region = "b", isos = "c", source = "d") - - expect_warning(join_ald_scenario2(l), NA) - - # testthat < 2.99.0.9000 seems to lack the `class` argument to expect_warning - # This function passes `class` only when testthat is >= 2.99.0.9000 - .args <- function(expr) { - supports_class <- packageVersion("testthat") >= "2.99.0.9000" - out <- list( - object = rlang::expr({{ expr }}), - regexp = "region_isos", - class = if (supports_class) "has_zero_rows" else NULL - ) - # Exclude `class = NULL` - out[!vapply(out, is.null, logical(1))] - } - - bad_scenario <- fake_scenario( - region = l$region, scenario_source = l$source, sector = "bad" - ) - # Silence warnings other than the first one - suppressWarnings( - do.call(expect_warning, .args(join_ald_scenario2(l, bad_scenario))) - ) - - bad_reg1 <- tibble(region = "bad", isos = l$isos, source = l$source) - do.call(expect_warning, .args(join_ald_scenario2(l, region_isos = bad_reg1))) - - bad_reg2 <- tibble(region = l$region, isos = "bad", source = l$source) - do.call(expect_warning, .args(join_ald_scenario2(l, region_isos = bad_reg2))) - - bad_reg3 <- tibble(region = l$region, isos = l$isos, source = "bad") - do.call(expect_warning, .args(join_ald_scenario2(l, region_isos = bad_reg3))) -}) - -test_that("include/excludes `plant_location` inside/outside a region", { - withr::local_options(lifecycle_verbosity = "quiet") - # styler: off - region_isos_toy <- tribble( - ~region, ~isos, ~source, - "north america", "us", "demo_2020", - "oecd", "de", "demo_2020", - "oecd", "fr", "demo_2020", - "china", "cn", "demo_2020", - ) - # styler: on - - out <- join_ald_scenario( - fake_matched(), - # We have isos to match all countries and regions; - region_isos = region_isos_toy, - # And we have asset-level data from all countries; - ald = fake_abcd(plant_location = c("de", "fr", "cn", "us")), - # But our scenario if is only relevant to Europe and China -- not US - scenario = fake_scenario(region = c("oecd", "china")) - ) - - # The output includes locations inside matching regions - - expect_true(all(unique(out$plant_location) %in% c("de", "fr", "cn"))) - # The output excludes locations outside matching regions - expect_false(any(unique(out$plant_location) %in% "us")) -}) - -test_that("outputs the same with upper/lower ald$sector or ald$technology", { - withr::local_options(lifecycle_verbosity = "quiet") - matched <- fake_matched() - ald <- fake_abcd() - scenario <- fake_scenario() - regions <- region_isos_stable - - out_lower <- join_ald_scenario(matched, ald, scenario, regions) - - upper_sector <- modify_at_(ald, "sector", toupper) - out_upper <- join_ald_scenario(matched, upper_sector, scenario, regions) - expect_equal(out_upper, out_lower) - - upper_technology <- modify_at_(ald, "technology", toupper) - out_upper <- join_ald_scenario(matched, upper_technology, scenario, regions) - expect_equal(out_upper, out_lower) -})