2DegreesInvesting/r2dii.climate.stress.test

run_stress_test() errors if term is integer

Closed this issue · 1 comments

term is likely too picky. It works with the double 1 but fails with the integer 1L.

devtools::load_all()
#> ℹ Loading r2dii.climate.stress.test

# Works with doubles
x <- capture.output(run_stress_test("bonds", term = 1))
#> Warning: Removed 21 rows because negative production compensation targets were set in late and sudden.
#>                    Negative absolute production is impossible

# Fails with integers
x <- capture.output(run_stress_test("bonds", term = 1L))
#> Warning: Removed 21 rows because negative production compensation targets were set in late and sudden.
#>                    Negative absolute production is impossible
#> Error: Problem with `mutate()` column `term`.
#> ℹ `term = dplyr::if_else(.data$term > 5, 5, .data$term)`.
#> x `false` must be a double vector, not an integer vector.

Created on 2021-11-07 by the reprex package (v2.0.1)

Very interesting catch, that should be tackled already for github ready release. The issue occurs here

dplyr::mutate(term = dplyr::if_else(.data$term > 5, 5, .data$term))
. If term is integer and term is numeric or reverse we have a mismatch between true and false vector.
As a quick fix I would suggest to convert term to numeric, or enforce term to be an integer throughout the package (would have to be changed soon though, since we plan on allowing terms that are not whole numbers), but maybe you have a better idea @maurolepore?
FYI @jacobvjk