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

Deparsed anonymous function call containing line breaks with expr_deparse() cannot be re-parsed with parse_expr() #1540

Closed
szmsu2011 opened this issue Jan 15, 2023 · 1 comment
Labels
expr:deparse feature a feature request or enhancement

Comments

@szmsu2011
Copy link

I noticed that if an expression containing line breaks (such as in an anonymous function call) is deparsed with expr_deparse(), it cannot be re-parsed back into an expression with parse_expr() unless I collapse them with "\n" first.

(x <- expr((function(x) {
    x <- x + 1
    x
})(1)))
#> (function(x) {
#>     x <- x + 1
#>     x
#> })(1)

x |>
  expr_deparse() |>
  parse_expr()
#> Error in parse(text = elt): <text>:2:0: unexpected end of input
#> 1: (function(x) {
#>    ^

x |>
  expr_deparse() |>
  paste(collapse = "\n") |>
  parse_expr()
#> (function(x) {
#>     x <- x + 1
#>     x
#> })(1)

x |>
  expr_deparse() |>
  parse(text = _)
#> expression((function(x) {
#>     x <- x + 1
#>     x
#> })(1))
@lionel- lionel- added expr:deparse feature a feature request or enhancement labels Feb 9, 2023
@lionel-
Copy link
Member

lionel- commented Feb 20, 2023

Useful previous discussion about the plural variant parse_exprs(): #808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expr:deparse feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants