Skip to content

Instantly share code, notes, and snippets.

@MrFlick
Created May 6, 2019 14:26
Show Gist options
  • Save MrFlick/fa3e40076c7082c1ed709a50539d40a6 to your computer and use it in GitHub Desktop.
Save MrFlick/fa3e40076c7082c1ed709a50539d40a6 to your computer and use it in GitHub Desktop.
list variables in quosure
# List a variable names (that are not functions) in
# a quosure
# ideas taken from https://adv-r.hadley.nz/expressions.html
find_vars <- function(x) {
extr <- function(x)
if (is.symbol(x)) {
as.character(x)
} else if (is.pairlist(x)) {
purrr::flatten_chr(purrr::map(as.list(x), find_vars))
} else if (is.call(x)) {
purrr::flatten_chr(purrr::map(as.list(x)[-1], find_vars))
} else {
NULL
}
extr(rlang::quo_squash(x))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment