Skip to content

Instantly share code, notes, and snippets.

@MarcinKosinski
Created December 8, 2020 18:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save MarcinKosinski/565de05f427d407fa410936905f5c9b0 to your computer and use it in GitHub Desktop.
# what it was
{if({my_stat} == "avg") {dplyr::summarise(., stat = mean(var_agg, na.rm = TRUE)) %>%
dplyr::pull(stat) %>% formattable::comma(label_digits)}
else if({my_stat} == "max") {dplyr::summarise(., stat = max(var_agg, na.rm = TRUE)) %>%
dplyr::pull(stat) %>% formattable::comma(label_digits)}
else if({my_stat} == "min") {dplyr::summarise(., stat = min(var_agg, na.rm = TRUE))
# what it can be
possible values of my_stat are renamed to so that `avg` is now `mean`
fun <- get(my_stat, envir = .GlobalEnv)
{dplyr::summarise(., stat = fun(var_agg, na.rm = TRUE)) %>%
dplyr::pull(stat) %>% formattable::comma(label_digits)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment