EmilHvitfeldt / paletteer

🎨🎨🎨 Collection of most color palettes in a single R package
https://emilhvitfeldt.github.io/paletteer/
Other
917 stars 45 forks source link

scale argument #4

Closed hadley closed 6 years ago

hadley commented 6 years ago

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 using deparse(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 than enquo(), since you only want to capture a name, not anything more complex)

EmilHvitfeldt commented 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.

hadley commented 6 years ago

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"
EmilHvitfeldt commented 6 years ago

ohhh of course! Thank you very much!