Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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