From 8fcd90e94865ccc7deed2d09d92fda16cec190a6 Mon Sep 17 00:00:00 2001 From: Monika Furdyna Date: Fri, 12 May 2023 16:56:54 +0200 Subject: [PATCH] Fix GH checks (#508) --- R/plot_emission_intensity.R | 6 ++-- R/plot_techmix.R | 6 ++-- R/plot_trajectory.R | 6 ++-- R/utils.R | 13 +++++---- tests/testthat/_snaps/sda.md | 28 +++++++++---------- tests/testthat/test-plot_emission_intensity.R | 7 +++-- tests/testthat/test-plot_techmix.R | 7 +++-- tests/testthat/test-plot_trajectory.R | 11 ++++---- .../testthat/test-qplot_emission_intensity.R | 2 +- vignettes/r2dii-plot.Rmd | 14 +++++----- 10 files changed, 52 insertions(+), 48 deletions(-) diff --git a/R/plot_emission_intensity.R b/R/plot_emission_intensity.R index eaa54326..58000111 100644 --- a/R/plot_emission_intensity.R +++ b/R/plot_emission_intensity.R @@ -31,9 +31,9 @@ plot_emission_intensity <- function(data, span_5yr = FALSE, convert_label = identity) { lifecycle::deprecate_soft( - when = "0.4.0", - what = "plot_emission_intensity(data = 'must be prepped already')", - details = api_warning_details("plot_emission_intensity") + when = "0.4.0", + what = "plot_emission_intensity(data = 'must be prepped already')", + details = api_warning_details("plot_emission_intensity") ) env <- list(data = substitute(data)) check_plot_emission_intensity(data, env = env) diff --git a/R/plot_techmix.R b/R/plot_techmix.R index 03e0b607..1332eed9 100644 --- a/R/plot_techmix.R +++ b/R/plot_techmix.R @@ -49,9 +49,9 @@ plot_techmix <- function(data, convert_label = identity, convert_tech_label = identity) { lifecycle::deprecate_soft( - when = "0.4.0", - what = "plot_techmix(data = 'must be prepped already')", - details = api_warning_details("plot_techmix") + when = "0.4.0", + what = "plot_techmix(data = 'must be prepped already')", + details = api_warning_details("plot_techmix") ) env <- list(data = substitute(data)) check_plot_techmix(data, env = env) diff --git a/R/plot_trajectory.R b/R/plot_trajectory.R index 062fd57b..e1952569 100644 --- a/R/plot_trajectory.R +++ b/R/plot_trajectory.R @@ -53,9 +53,9 @@ plot_trajectory <- function(data, value_col = "percentage_of_initial_production_by_scope", perc_y_scale = FALSE) { lifecycle::deprecate_soft( - when = "0.4.0", - what = "plot_trajectory(data = 'must be prepped already')", - details = api_warning_details("plot_trajectory") + when = "0.4.0", + what = "plot_trajectory(data = 'must be prepped already')", + details = api_warning_details("plot_trajectory") ) env <- list(data = substitute(data)) check_plot_trajectory(data, value_col = value_col, env = env) diff --git a/R/utils.R b/R/utils.R index 1d65716f..d199a798 100644 --- a/R/utils.R +++ b/R/utils.R @@ -38,7 +38,7 @@ abort_if_has_zero_rows <- function(data, env) { } hint_if_missing_names <- function(expr, like) { - rlang::with_handlers( + withCallingHandlers( expr, missing_names = function(err) { abort( @@ -81,11 +81,12 @@ abort_if_missing_names <- function(data, expected_names) { if (!all(unique(expected_names) %in% names(data))) { missing_names <- sort(setdiff(expected_names, names(data))) - abort(c( - "`data` must have all the expected names.", - x = glue("Missing names: {toString(missing_names)}.") - ), - class = "missing_names" + abort( + c( + "`data` must have all the expected names.", + x = glue("Missing names: {toString(missing_names)}.") + ), + class = "missing_names" ) } diff --git a/tests/testthat/_snaps/sda.md b/tests/testthat/_snaps/sda.md index 5634b38b..5b2dc267 100644 --- a/tests/testthat/_snaps/sda.md +++ b/tests/testthat/_snaps/sda.md @@ -4,18 +4,18 @@ sda Output # A tibble: 110 x 6 - sector year region scenario_source emission_factor_met~1 emiss~2 - - 1 cement 2020 advanced economies demo_2020 projected 0.0230 - 2 cement 2020 developing asia demo_2020 projected 0.0595 - 3 cement 2020 global demo_2020 projected 0.664 - 4 cement 2021 advanced economies demo_2020 projected 0.0232 - 5 cement 2021 developing asia demo_2020 projected 0.0594 - 6 cement 2021 global demo_2020 projected 0.665 - 7 cement 2022 advanced economies demo_2020 projected 0.0233 - 8 cement 2022 developing asia demo_2020 projected 0.0592 - 9 cement 2022 global demo_2020 projected 0.666 - 10 cement 2023 advanced economies demo_2020 projected 0.0235 - # ... with 100 more rows, and abbreviated variable names - # 1: emission_factor_metric, 2: emission_factor_value + sector year region scenario_source emission_factor_metric + + 1 cement 2020 advanced economies demo_2020 projected + 2 cement 2020 developing asia demo_2020 projected + 3 cement 2020 global demo_2020 projected + 4 cement 2021 advanced economies demo_2020 projected + 5 cement 2021 developing asia demo_2020 projected + 6 cement 2021 global demo_2020 projected + 7 cement 2022 advanced economies demo_2020 projected + 8 cement 2022 developing asia demo_2020 projected + 9 cement 2022 global demo_2020 projected + 10 cement 2023 advanced economies demo_2020 projected + # i 100 more rows + # i 1 more variable: emission_factor_value diff --git a/tests/testthat/test-plot_emission_intensity.R b/tests/testthat/test-plot_emission_intensity.R index b000fb14..ec0d069e 100644 --- a/tests/testthat/test-plot_emission_intensity.R +++ b/tests/testthat/test-plot_emission_intensity.R @@ -80,9 +80,10 @@ test_that("with n metrics in input outputs n lines", { options(warn = 0) -test_that("throws expected warning about API change",{ +test_that("throws expected warning about API change", { data <- head(filter(sda, sector == "cement")) expect_snapshot_error( - plot_emission_intensity(data), class = "warning" - ) + plot_emission_intensity(data), + class = "warning" + ) }) diff --git a/tests/testthat/test-plot_techmix.R b/tests/testthat/test-plot_techmix.R index 6881cb40..79cdf1d2 100644 --- a/tests/testthat/test-plot_techmix.R +++ b/tests/testthat/test-plot_techmix.R @@ -292,8 +292,9 @@ test_that("with no scenario for start year of 'projected' doesn't plot scenario options(warn = 0) -test_that("throws expected warning about API change",{ +test_that("throws expected warning about API change", { expect_snapshot_error( - plot_techmix(example_tech_mix()), class = "warning" - ) + plot_techmix(example_tech_mix()), + class = "warning" + ) }) diff --git a/tests/testthat/test-plot_trajectory.R b/tests/testthat/test-plot_trajectory.R index 9b3ad398..d5376ffa 100644 --- a/tests/testthat/test-plot_trajectory.R +++ b/tests/testthat/test-plot_trajectory.R @@ -165,7 +165,7 @@ test_that("with 0 as extreme value plots areas correctly", { technology == "oilcap", region == "global", scenario_source == "demo_2020" - ) %>% + ) %>% mutate( percentage_of_initial_production_by_scope = if_else( percentage_of_initial_production_by_scope >= 0, @@ -184,7 +184,7 @@ test_that("with 0 as extreme value plots areas correctly", { technology == "renewablescap", region == "global", scenario_source == "demo_2020" - ) %>% + ) %>% mutate( percentage_of_initial_production_by_scope = if_else( percentage_of_initial_production_by_scope <= 0, @@ -200,8 +200,9 @@ test_that("with 0 as extreme value plots areas correctly", { options(warn = 0) -test_that("throws expected warning about API change",{ +test_that("throws expected warning about API change", { expect_snapshot_error( - plot_trajectory(example_market_share()), class = "warning" - ) + plot_trajectory(example_market_share()), + class = "warning" + ) }) diff --git a/tests/testthat/test-qplot_emission_intensity.R b/tests/testthat/test-qplot_emission_intensity.R index ae31958a..07ca3137 100644 --- a/tests/testthat/test-qplot_emission_intensity.R +++ b/tests/testthat/test-qplot_emission_intensity.R @@ -5,7 +5,7 @@ test_that("outputs pretty labels", { metrics <- sort(unique(p$data$label)) pretty <- sort( c("Projected", "Corporate Economy", "Adjusted Scenario Demo", "Target Demo") - ) + ) expect_equal(metrics, pretty) }) diff --git a/vignettes/r2dii-plot.Rmd b/vignettes/r2dii-plot.Rmd index fe8d80ae..f4d8d0eb 100644 --- a/vignettes/r2dii-plot.Rmd +++ b/vignettes/r2dii-plot.Rmd @@ -95,8 +95,8 @@ Use `qplot_trajectory()` with `market_share`-like data. data <- matched %>% target_market_share(abcd, scenario = scenario_demo_2020, region_isos = region) %>% filter( - technology == "renewablescap", - region == "global", + technology == "renewablescap", + region == "global", scenario_source == "demo_2020" ) @@ -142,7 +142,7 @@ data <- matched %>% target_sda(abcd, co2_intensity_scenario = scenario, region_isos = region) %>% filter( sector == "cement", - region == "global", + region == "global", scenario_source == "demo_2020" ) @@ -158,9 +158,9 @@ data <- matched %>% target_sda(abcd, co2_intensity_scenario = scenario, region_isos = region) %>% filter( sector == "cement", - region == "global", + region == "global", scenario_source == "demo_2020" - ) + ) plot_emission_intensity(data, convert_label = to_title, span_5yr = TRUE) + labs( @@ -196,7 +196,7 @@ colours and legend labels. data <- sda %>% filter( sector == "cement", - region == "global", + region == "global", scenario_source == "demo_2020", year <= 2030 ) @@ -243,7 +243,7 @@ plot_trajectory(data) + x = "Year", y = "Production normalized to start year" ) + - theme(plot.margin = unit(c(0.5, 6, 0.5, 1), "cm")) #so the long labels fit + theme(plot.margin = unit(c(0.5, 6, 0.5, 1), "cm")) # so the long labels fit ``` * `plot_techmix()` - change time span, add 'label' column, apply custom colours