Skip to content
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

Parametrize thresholds #23

Open
maurolepore opened this issue Dec 13, 2023 · 0 comments
Open

Parametrize thresholds #23

maurolepore opened this issue Dec 13, 2023 · 0 comments

Comments

@maurolepore
Copy link
Contributor

maurolepore commented Dec 13, 2023

Thresholds require special treatment. It's very tricky to pass a complicated expression like ifelse() because it must be evaluated in the right environment, and that may need a change tiltIndicator.

Maybe for now it's best to do NULL for the default and allows only a single number as alternative input. To give finer grained control to the user we could take the thresholds directly from scenarios -- i.e. the user modifies scenarios to add the values of low_ and high_threshold they want.

---
title: "test"
output: github_document
params:
  low_threshold: !r expression(ifelse(scenarios$year == 2030, 1/9, 1/3))
  # !r 1/3 also works but maybe best to always call `eval()`
  high_threshold: !r expression(1/3)
---
params
#> $low_threshold
#> expression(ifelse(scenarios$year == 2030, 1/9, 1/3))
#> 
#> $high_threshold
#> expression(1/3)

f <- function(scenarios, low_threshold) {
  dplyr::mutate(scenarios, low_threshold = low_threshold)
}

scenarios <- tibble::tibble(year = c(2030, 2031, 2050))

f(scenarios, eval(params$low_threshold))
#> # A tibble: 3 × 2
#>    year low_threshold
#>   <dbl>         <dbl>
#> 1  2030         0.111
#> 2  2031         0.333
#> 3  2050         0.333


g <- function(scenarios, high_threshold) {
  dplyr::mutate(scenarios, high_threshold = high_threshold)
}

g(scenarios, eval(params$high_threshold))
#> # A tibble: 3 × 2
#>    year high_threshold
#>   <dbl>          <dbl>
#> 1  2030          0.333
#> 2  2031          0.333
#> 3  2050          0.333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant