Skip to content

Instantly share code, notes, and snippets.

@grayskripko
Created May 28, 2022 11:52
Show Gist options
  • Save grayskripko/901f5688e31a1a0a252f5c6003e977a4 to your computer and use it in GitHub Desktop.
Save grayskripko/901f5688e31a1a0a252f5c6003e977a4 to your computer and use it in GitHub Desktop.
quos and nse, hard case
group_in_func <- function(x, ...) {
x %>%
group_by(!!!(...)) %>%
summarise(sum(mpg))
}
list(quos(any_name=cyl == 6)) %>%
map(
group_in_func,
x=head(select(as_tibble(mtcars), 1:2), 5) %>% print())
# A tibble: 5 x 2
mpg cyl
<dbl> <dbl>
1 21 6
2 21 6
3 22.8 4
4 21.4 6
5 18.7 8
[[1]]
# A tibble: 2 x 2
any_name `sum(mpg)`
<lgl> <dbl>
1 FALSE 41.5
2 TRUE 63.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment