Skip to content

Instantly share code, notes, and snippets.

@grayskripko
Last active July 19, 2018 15:34
Show Gist options
  • Select an option

  • Save grayskripko/f09cc99ca494b0e95b7836ab47ee333b to your computer and use it in GitHub Desktop.

Select an option

Save grayskripko/f09cc99ca494b0e95b7836ab47ee333b to your computer and use it in GitHub Desktop.
NSE functions
# https://www.enchufa2.es/archives/programming-with-dplyr-by-using-dplyr.html
# 1. reminder
starwars_mean <- function(var) {
var <- enquo(var)
starwars %>% group_by(!!var)
}
starwars_mean(homeworld)
# 2. parsing a string inside
starwars_mean <- function(var) {
var <- as.name(var)
starwars %>% group_by(!!var)
}
# or even
starwars_mean <- function(var) starwars %>% group_by_at(var)
starwars_mean("homeworld")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment