Skip to content

Commit d11e5cc

Browse files
Export best_case_worst_case_impl function (#322)
* refactor * refactor
1 parent ab52513 commit d11e5cc

File tree

8 files changed

+101
-89
lines changed

8 files changed

+101
-89
lines changed

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(best_case_worst_case_emission_profile)
4+
export(best_case_worst_case_impl)
45
export(best_case_worst_case_sector_profile)
6+
export(polish_best_case_worst_case)
57
export(profile_emissions)
68
export(profile_emissions_impl)
79
export(profile_emissions_upstream)
@@ -10,6 +12,7 @@ export(profile_sector)
1012
export(profile_sector_impl)
1113
export(profile_sector_upstream)
1214
export(profile_sector_upstream_impl)
15+
export(rename_with_prefix)
1316
export(toy_emissions_profile_output)
1417
export(toy_emissions_profile_upstream_output)
1518
export(toy_profile_emissions_impl_output)

R/best_case_worst_case_impl.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
#' Calculate preliminary best case worst case results
2+
#'
3+
#' @param data Dataframe.
4+
#' @param col_group_by Dataframe column.
5+
#' @param col_risk Dataframe column.
6+
#' @param col_rank Dataframe column.
7+
#' @keywords internal
8+
#' @export
19
best_case_worst_case_impl <- function(data, col_group_by, col_risk, col_rank) {
210
data |>
311
compute_n_distinct_products() |>

R/example_data.R

Lines changed: 0 additions & 80 deletions
This file was deleted.

R/polish_best_case_worst_case.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#' Polish preliminary best case worst case results
2+
#'
3+
#' @param data Dataframe.
4+
#' @keywords internal
5+
#' @export
16
polish_best_case_worst_case <- function(data) {
27
data |>
38
select(-all_of(c(
@@ -9,6 +14,13 @@ polish_best_case_worst_case <- function(data) {
914
distinct()
1015
}
1116

17+
#' Rename using prefix
18+
#'
19+
#' @param data Dataframe.
20+
#' @param prefix String.
21+
#' @param match String.
22+
#' @keywords internal
23+
#' @export
1224
rename_with_prefix <- function(data, prefix, match = ".") {
1325
rename_with(data, ~ paste0(prefix, .x), .cols = matches(match))
1426
}
@@ -22,15 +34,6 @@ polish_best_case_worst_case_emissions_profile <- function(data) {
2234
))
2335
}
2436

25-
polish_best_case_worst_case_transition_risk_profile <- function(data) {
26-
data |>
27-
rename_with_prefix("transition_risk_profile_", match = c(
28-
"^best_case$",
29-
"^worst_case$",
30-
"^equal_weight$"
31-
))
32-
}
33-
3437
polish_best_case_worst_case_sector_profile <- function(data) {
3538
data |>
3639
rename_with_prefix("sector_profile_", match = c(

R/utils-test.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,26 @@ best_case_worst_case_emission_profile_sample <- function(companies_id = "any",
5555
emission_profile = emission_profile
5656
))
5757
}
58+
59+
example_best_case_worst_case_profile_ranking_product_level <- example_data_factory(
60+
# styler: off
61+
tribble(
62+
~companies_id, ~ep_product, ~benchmark, ~emission_profile, ~profile_ranking,
63+
"any", "one", "all", "low", 1.0,
64+
"any", "two", "all", "medium", 2.0,
65+
"any", "three", "all", "high", 3.0
66+
)
67+
# styler: on
68+
)
69+
70+
example_best_case_worst_case_reduction_targets_product_level <- example_data_factory(
71+
# styler: off
72+
tribble(
73+
~companies_id, ~ep_product, ~scenario_year, ~sector_profile, ~reduction_targets,
74+
"any", "one", "1.5C RPS_2030", "low", 1.0,
75+
"any", "two", "1.5C RPS_2030", "medium", 2.0,
76+
"any", "three", "1.5C RPS_2030", "high", 3.0
77+
)
78+
# styler: on
79+
)
80+

man/best_case_worst_case_impl.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/polish_best_case_worst_case.Rd

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rename_with_prefix.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)