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() doesn't look at attributes of calls #1475

Closed
moodymudskipper opened this issue Sep 2, 2022 · 3 comments
Closed

is_expression() doesn't look at attributes of calls #1475

moodymudskipper opened this issue Sep 2, 2022 · 3 comments

Comments

@moodymudskipper
Copy link

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.

@lionel-
Copy link
Member

lionel- commented Sep 3, 2022

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. {.

@moodymudskipper
Copy link
Author

moodymudskipper commented Sep 3, 2022

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().

@lionel-
Copy link
Member

lionel- commented Feb 16, 2023

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.

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