r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
500 stars 137 forks source link

Inconsistency between `is_call()` + `call_name()` vs `is_call(name = ...)` on quosure #1549

Closed mgirlich closed 1 year ago

mgirlich commented 1 year ago

I incorrectly used is_call() on a quosure and found this confusing inconsistency:

library(rlang)

x <- quo(desc(x))
is_call(x)
#> [1] TRUE
call_name(x)
#> [1] "desc"
is_call(x, "desc")
#> [1] FALSE

Created on 2023-02-03 with reprex v2.0.2

lionel- commented 1 year ago

I've been meaning to make is_call() return FALSE on quosures but it's been difficult a few years ago and is probably even more difficult now, regarding backwards compatibility.

In general though, is_call() is lower level than call_name() and the invariant you are looking for is not guaranteed. We do have invariants in terms of is_call_simple() though.