glue
glue copied to clipboard
Raw strings are not parsed correctly?
❯ r"{(\1\2)}"
[1] "(\\1\\2)"
❯ glue::glue('{r"{(\1\2)}"}')
()
Actually, that's not the right example, because the backslashes should have been doubled. Here is a problematic example:
r"{"}"
eval(parse(text = '{r"{"}"}'))
glue::glue('{r"{"}"}')
❯ r"{"}"
[1] "\""
❯ eval(parse(text = '{r"{"}"}'))
[1] "\""
❯ glue::glue('{r"{"}"}')
Error in parse(text = text, keep.source = FALSE) :
<text>:1:1: unexpected INCOMPLETE_STRING
1: r"{"
(Reprex produces wrong output, probably a knitr issue.)
Interestingly glue::glue('{r"(")"}') has different problem:
glue::glue('{r"(")"}')
#> Error in `glue_data()`:
#> ! Unterminated quote (")
Interestingly glue::glue('{r"(")"}') has different problem:
Yeah, it depends what you put in the raw string.
Given that glue’s parser is hand rolled and that raw strings are quite complex, I think it’s unlikely that it’s worth fixing this.