RMI-PACTA / r2dii.analysis

Tools to Calculate Climate Targets for Financial Portfolios
https://rmi-pacta.github.io/r2dii.analysis
Other
11 stars 9 forks source link

Align naming of metric-like columns for output of `target_*` functions #469

Open jdhoffa opened 7 months ago

jdhoffa commented 7 months ago

Current behaviour

target_market_share() outputs a column metric target_sda() outputs a column emission_factor_metric

Desired behaviour

Align so that both columns either output:

Supersedes #311


Brief description of the problem

library(r2dii.data)
library(r2dii.match)
library(r2dii.analysis)

matched <- loanbook_demo %>%
  match_name(abcd_demo) %>%
  prioritize()

# Calculate targets at portfolio level
matched %>%
  target_market_share(
    abcd = abcd_demo,
    scenario = scenario_demo_2020,
    region_isos = region_isos_demo
    )

#> # A tibble: 792 × 10
#>    sector     technology  year region scenario_source metric     production
#>    <chr>      <chr>      <int> <chr>  <chr>           <chr>           <dbl>
#>  1 automotive electric    2020 global demo_2020       projected     324592.
#>  2 automotive electric    2020 global demo_2020       target_cps    324592.
#>  3 automotive electric    2020 global demo_2020       target_sds    324592.
#>  4 automotive electric    2020 global demo_2020       target_sps    324592.
#>  5 automotive electric    2021 global demo_2020       projected     339656.
#>  6 automotive electric    2021 global demo_2020       target_cps    329191.
#>  7 automotive electric    2021 global demo_2020       target_sds    352505.
#>  8 automotive electric    2021 global demo_2020       target_sps    330435.
#>  9 automotive electric    2022 global demo_2020       projected     354720.
#> 10 automotive electric    2022 global demo_2020       target_cps    333693.
#> # ℹ 782 more rows
#> # ℹ 3 more variables: technology_share <dbl>, scope <chr>,
#> #   percentage_of_initial_production_by_scope <dbl>

# Calculate targets at company level
out_market_share <- matched %>%
  target_market_share(
  abcd = abcd_demo,
  scenario = scenario_demo_2020,
  region_isos = region_isos_demo
  ) 

out_sda <- matched %>% 
  target_sda(
    abcd = abcd_demo,
    co2_intensity_scenario = co2_intensity_scenario_demo,
    region_isos = region_isos_demo
  )
#> Warning: Removing rows in abcd where `emission_factor` is NA

# note that the column names of the metrics are different
all_names <- c(names(out_sda), names(out_market_share))
all_names[grep("metric", all_names)]
#> [1] "emission_factor_metric" "metric"

Created on 2024-02-06 with reprex v2.1.0

AB#9902

jdhoffa commented 7 months ago

See also #313 for some useful discussion.