-
Notifications
You must be signed in to change notification settings - Fork 1
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
sector_profile()
now accounts for unmatched type
, sector
or subsector
#739
Conversation
sector*()
functions now handle missing "benchmark"
@Tilmon (cc' @AnneSchoenauer) I'm struggling to see the difference between the case "unmatched products" and the case "missing benchmarks". For However, for Your #738 (comment) seems to support the idea that these two cases are no different:
The best way to clarify things is through a reproducible example that you are familiar with because it's based on the one you created in this GoogleSheet. At this point I'm so confused that I don't know if you think it shows one or both cases, but I hope it's a good start. reprexlibrary(tibble)
devtools::load_all()
#> ℹ Loading tiltIndicator
packageVersion("tiltIndicator")
#> [1] '0.0.0.9211'
withr::local_options(list(tibble.print_max = Inf, width = 500))
companies <- tribble(
~companies_id, ~clustered, ~activity_uuid_product_uuid, ~tilt_sector, ~tilt_subsector, ~type, ~sector, ~subsector,
"a", "a", "a", "a", "a", "ipr", "total", "energy",
"a", "a", "a", "a", "a", "weo", "total", "energy",
"a", "b", "unmatched", "unmatched", "unmatched", "unmatched", "unmatched", "unmatched",
"a", "c", "unmatched", "c", "c", "ipr", "land use", "land use",
"a", "c", "unmatched", "c", "c", "weo", NA, NA
)
scenarios <- tribble(
~sector, ~subsector, ~year, ~reductions, ~type, ~scenario,
"total", "energy", 2050, 1.0, "ipr", "a",
"total", "energy", 2050, 0.6, "weo", "a",
"land use", "land use", 2050, 0.3, "ipr", "a"
)
sector_profile(companies, scenarios) |> unnest_product()
#> # A tibble: 5 × 11
#> companies_id grouped_by risk_category profile_ranking clustered activity_uuid_product_uuid tilt_sector scenario year type tilt_subsector
#> <chr> <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <dbl> <chr> <chr>
#> 1 a ipr_a_2050 high 1 a a a a 2050 ipr a
#> 2 a weo_a_2050 medium 0.6 a a a a 2050 weo a
#> 3 a <NA> <NA> NA b unmatched unmatched <NA> NA unmatched unmatched
#> 4 a ipr_a_2050 low 0.3 c unmatched c a 2050 ipr c
#> 5 a <NA> <NA> NA c unmatched c <NA> NA weo c
sector_profile(companies, scenarios) |> unnest_company()
#> # A tibble: 8 × 4
#> companies_id grouped_by risk_category value
#> <chr> <chr> <chr> <dbl>
#> 1 a ipr_a_2050 high 0.25
#> 2 a ipr_a_2050 medium 0
#> 3 a ipr_a_2050 low 0.25
#> 4 a ipr_a_2050 <NA> 0.5
#> 5 a weo_a_2050 high 0
#> 6 a weo_a_2050 medium 0.333
#> 7 a weo_a_2050 low 0
#> 8 a weo_a_2050 <NA> 0.667 It it possible that this is already all you want? If yes, we're done and I can close this PR. If not, what do you expect? |
Hi @maurolepore , let me respond to the points you raised below. I first start with a more detailed description of how to think about the two different cases and then explain why I think the reprex is unfortunately wrong. Description of the "two cases"
I must admit that I find the difference in the case of
Reprex
So the reprex example is great to discuss the issue. I see two problems with the reprex you shared, one on product-level and one on company-level:
I hope this helps. Let me know if it does! P.S. I realize my comment here was not very helpful, as it's not wrong but leads to more confusion about the two different cases.
I agree that in this case the unmatched value in sector is the important relationship. |
sector*()
functions now handle missing "benchmark"sector*()
functions should preserve "missing benchmarks"
7e45582
to
6e56a7d
Compare
Noted (#784). Thanks! |
NA
s in benchmark-columns should yieldNA
s inrisk_category
(except "all") #638emissions*()
functions preserve unmatched products and missing benchmarks #639reprex of the approved behaviour
--
Given a
clustered
matching one but not a secondtype
of scenario, when thescenarios
dataset has the two types, then the secondtype
and its correspondingscenario
are still present ingrouped_by
, and the mismatch is reflected correctly in thevalue
.The expected behaviour is captured in this GoogleSheet and explained in #739 (comment) (thanks @Tilmon).
TODO
EXCEPTIONS