rlang
rlang copied to clipboard
is_expression() doesn't look at attributes of calls
From ?rlang::is_expression:
In rlang, an expression is the return type of parse_expr(), the set of objects that can be obtained from parsing R code
x <- quote(a(1)(2))
attr(x[[1]], "foo") <- "bar"
# I'm ok with this
rlang::expr_deparse(x)
#> [1] "a(1)(2)"
# But then doesn't this mean this should be FALSE ?
rlang::is_expression(x)
#> [1] TRUE
Created on 2022-09-02 by the reprex package (v2.0.1)
For context in S4 objects we can find calls with attributes.
That makes sense. But this might be a bit tricky, need to be careful about srcref attributes created by the parser on some language objects, e.g. {.
Ah indeed good catch, I believe this implies that using current definition quote({a}) is not an expression either.
Maybe we could have is_expression(x, ignore_attr = TRUE, ignore_srcref = TRUE) , these are arguments we find in waldo::compare().
Maybe we could have is_expression(x, ignore_attr = TRUE, ignore_srcref = TRUE) , these are arguments we find in waldo::compare().
I'm not looking into extending the feature set of is_expression() further. I now regret having added it to the package because it doesn't seem worth the maintenance effort.