rlang
rlang copied to clipboard
is_expression() returns FALSE on quoted function definitions
From ?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
expr <- rlang::parse_expr("function(x) {x}")
rlang::is_expression(expr)
#> [1] FALSE
I believe the reason might be that expr[[2]] is a pairlist, not a symbol or call, since the doc also says :
is_expression() returns TRUE if the input is either a symbolic object or a syntactic literal. If a call, the elements of the call must all be expressions as well. Unparsable calls are not considered expressions in this narrow definition.
There might be a contradiction between these 2 quoted extracts.
I understand the appeal of the consistency of the 2nd definition (the one that is actually applied), but the 1st definition is more intuitive, maybe a pairlist_as_language arg and/or a note in the doc would help ?
May also be because of srcrefs. This needs some special-casing, not an additional arg. I don't think the doc needs to be precise.