2DegreesInvesting / tiltIndicator

Implement the core business logic of the tilt indicators
https://2degreesinvesting.github.io/tiltIndicator/
GNU General Public License v3.0
1 stars 1 forks source link

In the internal `example_scenarios()` the column `reductions` should be a double #727

Open maurolepore opened 7 months ago

maurolepore commented 7 months ago

Expected a double but got a character:

typeof(tiltIndicator:::example_scenarios()$reductions)
#> [1] "character"

Thanks @kalashsinghal

For the record, the goal of this internal function is to create tiny toy data for tests, but we're not forced to use it so in the meantime we can use something like this:

scenarios <- tibble::tribble(
  ~sector, ~subsector,  ~year, ~reductions, ~type, ~scenario,
  "total",   "energy", "2050",           1, "ipr",       "a"
)

typeof(scenarios$reductions)
#> [1] "double"

Alternatively you may define a potential solution in tests/testthat/helper.R

devtools::load_all()
#> ℹ Loading tiltIndicator

# tests/testthat/helper.R
FIXME_example_scenarios <- function(...) {
  example_scenarios(...) |> 
    mutate(reductions = as.double(reductions))
}

# You can now use it in any test. For example
FIXME_example_scenarios(!!aka("xsector") := c("total", "unmatched"))
#> # A tibble: 2 × 6
#>   sector    subsector year  reductions type  scenario
#>   <chr>     <chr>     <chr>      <dbl> <chr> <chr>   
#> 1 total     energy    2050           1 ipr   a       
#> 2 unmatched energy    2050           1 ipr   a

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