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

Styler throws "not parseable" error on parseable script using unprintable ASCII character literal "\1" #991

Open
MichaelChirico opened this issue Aug 27, 2022 · 5 comments

Comments

@MichaelChirico
Copy link
Contributor

styler::style_text(R'( "\1" )')
Error in `value[[3L]]()`:
! Styling resulted in code that isn't parsable. This should not happen. Please file a bug report on GitHub (https://github.com/r-lib/styler/issues) using a reprex.
Run `rlang::last_error()` to see where the error occurred.

Of course, this is parseable:

parse(text = R'( "\1" )')
# expression("\1")
@MichaelChirico MichaelChirico changed the title Styler throws "not parseable" error on parseable script using unprintable ASCII character literall Styler throws "not parseable" error on parseable script using unprintable ASCII character literal Aug 27, 2022
@MichaelChirico MichaelChirico changed the title Styler throws "not parseable" error on parseable script using unprintable ASCII character literal Styler throws "not parseable" error on parseable script using unprintable ASCII character literal "\1" Aug 27, 2022
@MichaelChirico
Copy link
Contributor Author

MichaelChirico commented Aug 27, 2022

Oh, I think this is because of the R bug (https://bugs.r-project.org/show_bug.cgi?id=18323; fixed in devel, and maybe 4.2.1?); lintr has this helper as a workaround:

https://github.com/r-lib/lintr/blob/7d8c2c4891961d0a99d52d42c513ecb9fe851bea/R/get_source_expressions.R#L686-L688

@krlmlr
Copy link
Member

krlmlr commented Sep 7, 2022

Careful:

r"{(\1\2)}"
#> [1] "(\\1\\2)"
"(\1\2)"
#> [1] "(\001\002)"

Created on 2022-09-07 by the reprex package (v2.0.1)

@lorenzwalthert
Copy link
Collaborator

Sorry I can't follow. @MichaelChirico if you want this fixed, I am afraid you have to make a PR (or @krlmlr can do).

@MichaelChirico
Copy link
Contributor Author

Kirill, to clarify, I'm using raw strings to avoid two-layer-escaping -- your latter example is the code that causes issues for styler. Look at the getParseData output for it -- the column numbers are wrong (on 4.2.0 and earlier, at least). lintr's workaround corrects the column numbers.

@krlmlr
Copy link
Member

krlmlr commented Oct 23, 2022

We can work around, or accept that you need recent R to style these literals. I don't have a strong preference.

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

No branches or pull requests

3 participants