Closed markfairbanks closed 3 years ago
Ah, this is a very nice find. Thanks a lot.
This seems to work:
get_used <- function(x) {
if (is.symbol(x)) {
as.character(x)
} else {
unique(unlist(lapply(x[-1], get_used)))
}
}
test_df <- data.frame(x = 1:3, y = 1:3, z = 1:3)
var <- 1
# test_expr <- quote(1 * 2) # Returns NULL
test_expr <- quote(x * var + ifelse(x < y, 1, 0) + n())
used <- get_used(test_expr)
used[used %in% names(test_df)]
#> [1] "x" "y"
There would also need to be some sort of if
statement for the case where no vars were used and it returns NULL
Comparison to dplyr: