Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target_market_share now correctly handles input scenario with a hyphen in name #464

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# r2dii.analysis (development version)

* `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).

# r2dii.analysis 0.3.0
Expand Down
7 changes: 6 additions & 1 deletion R/target_market_share.R
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,12 @@ separate_metric_from_name <- function(data) {
name = sub("(production)_", "\\1-", .data$name),
name = sub("(technology_share)_", "\\1-", .data$name)
) %>%
tidyr::separate(.data$name, into = c("name", "metric"), sep = "-")
tidyr::separate(
.data$name,
into = c("name", "metric"),
sep = "-",
extra = "merge"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shockingly simple fix :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My favourite kind!

I am going to try to address your knit comment while I'm here also.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah actually no I'm not. That new function is still experimental, I will wait until it is stable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New issue #471

)
}

check_input_for_crucial_columns <- function(data, abcd, scenario) {
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-target_market_share.R
Original file line number Diff line number Diff line change
Expand Up @@ -1428,3 +1428,17 @@ test_that("with `abcd` with `NA` for start year, replaces `NA` with 0 (#423)", {

expect_equal(out$production, c(0, 1))
})

test_that("correctly splits scenario names with hyphen #425", {

out <- target_market_share(
fake_matched(),
fake_abcd(),
fake_scenario(scenario = "1.5c-scen"),
region_isos_stable
) %>%
filter(grepl("target", metric))

expect_equal(unique(out$metric), "target_1.5c-scen")

})
Loading