Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_expression() returns FALSE on quoted function definitions #1499

Closed
moodymudskipper opened this issue Oct 2, 2022 · 1 comment
Closed

Comments

@moodymudskipper
Copy link

moodymudskipper commented Oct 2, 2022

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 ?

@lionel-
Copy link
Member

lionel- commented Oct 3, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants