Styler throws "not parseable" error on parseable script using unprintable ASCII character literal "\1"
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")
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
Careful:
r"{(\1\2)}"
#> [1] "(\\1\\2)"
"(\1\2)"
#> [1] "(\001\002)"
Created on 2022-09-07 by the reprex package (v2.0.1)
Sorry I can't follow. @MichaelChirico if you want this fixed, I am afraid you have to make a PR (or @krlmlr can do).
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.
We can work around, or accept that you need recent R to style these literals. I don't have a strong preference.