Closed hadley closed 6 years ago
I agree that the scale argument shouldn't be there, its a ugly hack to make the functions work with both strings and symbols. The underlying problem is best described in the following reprex
fun_a <- function(x) {
x <- rlang::quo_name(rlang::ensym(x))
x
}
fun_b <- function(x) {
x <- rlang::quo_name(rlang::ensym(x))
x <- fun_a(x = x)
x
}
fun_a("a")
#> [1] "a"
fun_a(a)
#> [1] "a"
fun_b("a")
#> [1] "x"
fun_b(a)
#> [1] "x"
I would want all the 4 call to return "a"
but have been unsuccessful so far.
Since fun_b()
wraps a function that uses tidy evaluation, it needs to quote and unquote:
fun_a <- function(x) {
x <- rlang::quo_name(rlang::ensym(x))
x
}
fun_b <- function(x) {
x <- rlang::ensym(x)
x <- fun_a(!!x)
x
}
fun_a("a")
#> [1] "a"
fun_a(a)
#> [1] "a"
fun_b("a")
#> [1] "a"
fun_b(a)
#> [1] "a"
ohhh of course! Thank you very much!
I think it's generally bad practice to have an argument that controls whether or not a variable is automatically quoted — and it's definitely not in keeping with tidy evaluation. I'd suggest either eliminating it (and relying on people using
!!
) or usingdeparse(substitute(package))
to make it clear that you're not actually using tidyeval.(If you do want to continue using tidyeval, I'd recommend using
ensym()
rather thanenquo()
, since you only want to capture a name, not anything more complex)