Skip to content

Commit

Permalink
Fix GH checks (#508)
Browse files Browse the repository at this point in the history
  • Loading branch information
MonikaFu authored May 12, 2023
1 parent 54a13f2 commit 8fcd90e
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 48 deletions.
6 changes: 3 additions & 3 deletions R/plot_emission_intensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions R/plot_techmix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions R/plot_trajectory.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
)
}

Expand Down
28 changes: 14 additions & 14 deletions tests/testthat/_snaps/sda.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
sda
Output
# A tibble: 110 x 6
sector year region scenario_source emission_factor_met~1 emiss~2
<chr> <dbl> <chr> <chr> <chr> <dbl>
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
<chr> <dbl> <chr> <chr> <chr>
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 <dbl>

7 changes: 4 additions & 3 deletions tests/testthat/test-plot_emission_intensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
})
7 changes: 4 additions & 3 deletions tests/testthat/test-plot_techmix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
})
11 changes: 6 additions & 5 deletions tests/testthat/test-plot_trajectory.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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"
)
})
2 changes: 1 addition & 1 deletion tests/testthat/test-qplot_emission_intensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
14 changes: 7 additions & 7 deletions vignettes/r2dii-plot.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand All @@ -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(
Expand Down Expand Up @@ -196,7 +196,7 @@ colours and legend labels.
data <- sda %>%
filter(
sector == "cement",
region == "global",
region == "global",
scenario_source == "demo_2020",
year <= 2030
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8fcd90e

Please sign in to comment.