diff --git a/R/emissions_profile_any_at_product_level.R b/R/emissions_profile_any_at_product_level.R index bc81c3cc3..449e25f79 100644 --- a/R/emissions_profile_any_at_product_level.R +++ b/R/emissions_profile_any_at_product_level.R @@ -10,7 +10,7 @@ emissions_profile_any_at_product_level <- function(companies, .co2 <- prepare_co2(co2, low_threshold, high_threshold) .co2 |> - emissions_profile_any_compute_profile_ranking() |> + epa_compute_profile_ranking() |> add_risk_category(low_threshold, high_threshold) |> join_companies(.companies) |> epa_select_cols_at_product_level() |> diff --git a/R/emissions_profile_any_compute_profile_ranking.R b/R/epa_compute_profile_ranking.R similarity index 82% rename from R/emissions_profile_any_compute_profile_ranking.R rename to R/epa_compute_profile_ranking.R index f1a7305f5..4a2d7f202 100644 --- a/R/emissions_profile_any_compute_profile_ranking.R +++ b/R/epa_compute_profile_ranking.R @@ -1,9 +1,15 @@ #' Add values to categorize #' +#' @description +#' `r lifecycle::badge("deprecated")` +#' +#' This function was deprecated because it's internal. Users don't need to +#' interact with the function itself. +#' #' @param data A "co2-like" data frame -- i.e. containing products or #' upstream-products (a.k.a. inputs). #' -#' @family pre-processing helpers +#' @keywords internal #' #' @return The input data frame with the additional columns `grouped_by` and #' `profile_ranking` and one row per benchmark per company. @@ -23,7 +29,16 @@ #' inputs <- read_csv(toy_emissions_profile_upstream_products_ecoinvent()) #' inputs |> emissions_profile_any_compute_profile_ranking() emissions_profile_any_compute_profile_ranking <- function(data) { - check_emissions_profile_any_compute_profile_ranking(data) + lifecycle::deprecate_warn( + "0.0.0.9109", + "emissions_profile_any_compute_profile_ranking()", + details = "This function is now internal." + ) + epa_compute_profile_ranking(data) +} + +epa_compute_profile_ranking <- function(data) { + check_epa_compute_profile_ranking(data) exclude <- short_isic(data) | is.na(get_column(data, aka("isic"))) | @@ -31,11 +46,11 @@ emissions_profile_any_compute_profile_ranking <- function(data) { list(!exclude, exclude) |> map(\(x) filter(data, x)) |> - map_df(\(data) emissions_profile_any_compute_profile_ranking_impl(data)) |> + map_df(\(data) epa_compute_profile_ranking_impl(data)) |> assign_na_to_profile_ranking_in_special_cases() } -emissions_profile_any_compute_profile_ranking_impl <- function(data) { +epa_compute_profile_ranking_impl <- function(data) { benchmarks <- set_names(epa_benchmarks(data), flat_benchmarks(data)) out <- map_df(benchmarks, \(x) add_rank(data, x), .id = "grouped_by") @@ -43,7 +58,7 @@ emissions_profile_any_compute_profile_ranking_impl <- function(data) { relocate(out, all_of(related_cols)) } -check_emissions_profile_any_compute_profile_ranking <- function(data) { +check_epa_compute_profile_ranking <- function(data) { crucial <- c(aka("tsector"), aka("xunit"), aka("isic"), aka("co2footprint")) walk(crucial, \(pattern) check_matches_name(data, pattern)) } diff --git a/man/emissions_profile_any_compute_profile_ranking.Rd b/man/emissions_profile_any_compute_profile_ranking.Rd index e57c4b607..655e2a45b 100644 --- a/man/emissions_profile_any_compute_profile_ranking.Rd +++ b/man/emissions_profile_any_compute_profile_ranking.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/emissions_profile_any_compute_profile_ranking.R +% Please edit documentation in R/epa_compute_profile_ranking.R \name{emissions_profile_any_compute_profile_ranking} \alias{emissions_profile_any_compute_profile_ranking} \title{Add values to categorize} @@ -15,7 +15,10 @@ The input data frame with the additional columns \code{grouped_by} and \code{profile_ranking} and one row per benchmark per company. } \description{ -Add values to categorize +\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 because it's internal. Users don't need to +interact with the function itself. } \examples{ library(tiltToyData) @@ -30,10 +33,4 @@ products |> emissions_profile_any_compute_profile_ranking() inputs <- read_csv(toy_emissions_profile_upstream_products_ecoinvent()) inputs |> emissions_profile_any_compute_profile_ranking() } -\seealso{ -Other pre-processing helpers: -\code{\link{sector_profile_any_pivot_type_sector_subsector}()}, -\code{\link{sector_profile_any_prepare_scenario}()}, -\code{\link{sector_profile_any_prune_companies}()} -} -\concept{pre-processing helpers} +\keyword{internal} diff --git a/man/sector_profile_any_pivot_type_sector_subsector.Rd b/man/sector_profile_any_pivot_type_sector_subsector.Rd index ca5d62d11..b49618eb7 100644 --- a/man/sector_profile_any_pivot_type_sector_subsector.Rd +++ b/man/sector_profile_any_pivot_type_sector_subsector.Rd @@ -34,7 +34,6 @@ companies } \seealso{ Other pre-processing helpers: -\code{\link{emissions_profile_any_compute_profile_ranking}()}, \code{\link{sector_profile_any_prepare_scenario}()}, \code{\link{sector_profile_any_prune_companies}()} } diff --git a/man/sector_profile_any_prepare_scenario.Rd b/man/sector_profile_any_prepare_scenario.Rd index 83bd31cc6..6f399b087 100644 --- a/man/sector_profile_any_prepare_scenario.Rd +++ b/man/sector_profile_any_prepare_scenario.Rd @@ -28,7 +28,6 @@ sector_profile_any_prepare_scenario(raw_scenarios) } \seealso{ Other pre-processing helpers: -\code{\link{emissions_profile_any_compute_profile_ranking}()}, \code{\link{sector_profile_any_pivot_type_sector_subsector}()}, \code{\link{sector_profile_any_prune_companies}()} } diff --git a/man/sector_profile_any_prune_companies.Rd b/man/sector_profile_any_prune_companies.Rd index fcbcde972..cf66dc37d 100644 --- a/man/sector_profile_any_prune_companies.Rd +++ b/man/sector_profile_any_prune_companies.Rd @@ -39,7 +39,6 @@ sector_profile_any_prune_companies(companies) } \seealso{ Other pre-processing helpers: -\code{\link{emissions_profile_any_compute_profile_ranking}()}, \code{\link{sector_profile_any_pivot_type_sector_subsector}()}, \code{\link{sector_profile_any_prepare_scenario}()} } diff --git a/tests/testthat/_snaps/deprecated.md b/tests/testthat/_snaps/deprecated.md new file mode 100644 index 000000000..522f9269e --- /dev/null +++ b/tests/testthat/_snaps/deprecated.md @@ -0,0 +1,10 @@ +# emissions_profile_any_compute_profile_ranking() is deprecated + + Code + expect_equal(epa_compute_profile_ranking(co2), + emissions_profile_any_compute_profile_ranking(co2)) + Condition + Warning: + `emissions_profile_any_compute_profile_ranking()` was deprecated in tiltIndicator 0.0.0.9109. + i This function is now internal. + diff --git a/tests/testthat/test-deprecated.R b/tests/testthat/test-deprecated.R index 64500cf9b..99c4f9ab2 100644 --- a/tests/testthat/test-deprecated.R +++ b/tests/testthat/test-deprecated.R @@ -84,3 +84,13 @@ test_that("xstr_polish_output_at_company_level() throws a deprecation warning", ) expect_warning(xstr_polish_output_at_company_level(result), "deprecated") }) + +test_that("emissions_profile_any_compute_profile_ranking() is deprecated", { + co2 <- example_products() + expect_snapshot( + expect_equal( + epa_compute_profile_ranking(co2), + emissions_profile_any_compute_profile_ranking(co2) + ) + ) +}) diff --git a/tests/testthat/test-emissions_profile_any_compute_profile_ranking.R b/tests/testthat/test-epa_compute_profile_ranking.R similarity index 83% rename from tests/testthat/test-emissions_profile_any_compute_profile_ranking.R rename to tests/testthat/test-epa_compute_profile_ranking.R index e90621407..93b8bc007 100644 --- a/tests/testthat/test-emissions_profile_any_compute_profile_ranking.R +++ b/tests/testthat/test-epa_compute_profile_ranking.R @@ -1,15 +1,15 @@ test_that("works with any 'co2-like' dataset", { co2 <- example_products() - expect_no_error(emissions_profile_any_compute_profile_ranking(co2)) + expect_no_error(epa_compute_profile_ranking(co2)) co2 <- example_inputs() - expect_no_error(emissions_profile_any_compute_profile_ranking(co2)) + expect_no_error(epa_compute_profile_ranking(co2)) }) test_that("adds columns `grouped_by` and `profile_ranking` to the left", { co2 <- example_products() - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) new_names <- c("grouped_by", "profile_ranking") expect_equal(names(out)[1:2], new_names) @@ -18,7 +18,7 @@ test_that("adds columns `grouped_by` and `profile_ranking` to the left", { test_that("with one company, adds one row per benchmark per company", { co2 <- example_products() - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) number_of_benchmarks <- length(flat_benchmarks(co2)) expect_equal(nrow(out), number_of_benchmarks) @@ -27,7 +27,7 @@ test_that("with one company, adds one row per benchmark per company", { test_that("with two companies, adds one row per benchmark per company", { co2 <- example_products(!!aka("id") := c("a", "b")) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) number_of_benchmarks <- length(flat_benchmarks(co2)) expect_equal(nrow(out), 2 * number_of_benchmarks) @@ -38,26 +38,26 @@ test_that("without crucial columns errors gracefully", { crucial <- aka("tsector") bad <- select(co2, -all_of(crucial)) - expect_error(emissions_profile_any_compute_profile_ranking(bad), crucial) + expect_error(epa_compute_profile_ranking(bad), crucial) crucial <- aka("xunit") bad <- select(co2, -all_of(crucial)) - expect_error(emissions_profile_any_compute_profile_ranking(bad), crucial) + expect_error(epa_compute_profile_ranking(bad), crucial) crucial <- aka("isic") bad <- select(co2, -all_of(crucial)) - expect_error(emissions_profile_any_compute_profile_ranking(bad), crucial) + expect_error(epa_compute_profile_ranking(bad), crucial) crucial <- aka("co2footprint") bad <- select(co2, -all_of(crucial)) - expect_error(emissions_profile_any_compute_profile_ranking(bad), crucial) + expect_error(epa_compute_profile_ranking(bad), crucial) }) test_that("`profile_ranking` is `1` for all maximum `*co2_footprint`", { pattern <- aka("co2footprint") co2 <- example_products(!!pattern := c(1, 2, 3, 3, 3)) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) max <- filter(out, .data[[pattern]] == max(.data[[pattern]])) expect_true(all(max$profile_ranking == 1.0)) @@ -69,7 +69,7 @@ test_that("with inputs, `profile_ranking` is `1` for all maximum `*co2_footprint pattern <- paste0("input_", aka("co2footprint")) co2 <- example_inputs(!!pattern := c(1, 2, 3, 3, 3)) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) max <- filter(out, .data[[pattern]] == max(.data[[pattern]])) expect_true(all(max$profile_ranking == 1.0)) @@ -83,7 +83,7 @@ test_that("`profile_ranking` excludes-rows and is `NA` where `tilt_sector` is `N co2 <- example_products(!!pattern := c("'1234'", "'1234'", exclude)) co2[find_co2_footprint(co2)] <- c(3, 2, 1) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) ranking <- unique(out$profile_ranking) expected <- c(rank_proportion(c(3, 2)), NA) @@ -101,7 +101,7 @@ test_that("with inputs, `profile_ranking` excludes-rows and is `NA` where `tilt_ co2 <- example_inputs(!!pattern := c("'1234'", "'1234'", exclude)) co2[find_co2_footprint(co2)] <- c(3, 2, 1) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) ranking <- unique(out$profile_ranking) expected <- c(rank_proportion(c(3, 2)), NA) @@ -119,7 +119,7 @@ test_that("`profile_ranking` excludes-rows and is `NA` where `*isic_4digit` is ` co2 <- example_products(!!pattern := c("'1234'", "'1234'", exclude)) co2[find_co2_footprint(co2)] <- c(3, 2, 1) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) ranking <- unique(out$profile_ranking) expected <- c(rank_proportion(c(3, 2)), NA) @@ -137,7 +137,7 @@ test_that("with inputs, `profile_ranking` excludes-rows and is `NA` where `*isic co2 <- example_inputs(!!pattern := c("'1234'", "'1234'", exclude)) co2[find_co2_footprint(co2)] <- c(3, 2, 1) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) ranking <- unique(out$profile_ranking) expected <- c(rank_proportion(c(3, 2)), NA) @@ -155,7 +155,7 @@ test_that("`profile_ranking` excludes-rows and is `NA` where `*isic_4digit` has co2 <- example_products(!!pattern := c("'1234'", "'1234'", exclude)) co2[find_co2_footprint(co2)] <- c(3, 2, 1) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) ranking <- unique(out$profile_ranking) expected <- c(rank_proportion(c(3, 2)), NA) @@ -173,7 +173,7 @@ test_that("with inputs, `profile_ranking` excludes-rows and is `NA` where `*isic co2 <- example_inputs(!!pattern := c("'1234'", "'1234'", exclude)) co2[find_co2_footprint(co2)] <- c(3, 2, 1) - out <- emissions_profile_any_compute_profile_ranking(co2) + out <- epa_compute_profile_ranking(co2) ranking <- unique(out$profile_ranking) expected <- c(rank_proportion(c(3, 2)), NA)