Created
May 6, 2019 14:26
-
-
Save MrFlick/fa3e40076c7082c1ed709a50539d40a6 to your computer and use it in GitHub Desktop.
list variables in quosure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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