glue icon indicating copy to clipboard operation
glue copied to clipboard

Raw strings are not parsed correctly?

Open gaborcsardi opened this issue 3 years ago • 1 comments

❯ r"{(\1\2)}"
[1] "(\\1\\2)"
❯ glue::glue('{r"{(\1\2)}"}')
()

gaborcsardi avatar Dec 16 '21 18:12 gaborcsardi

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

gaborcsardi avatar Apr 28 '22 10:04 gaborcsardi

Interestingly glue::glue('{r"(")"}') has different problem:

glue::glue('{r"(")"}')
#> Error in `glue_data()`:
#> ! Unterminated quote (")

hadley avatar Jan 25 '23 23:01 hadley

Interestingly glue::glue('{r"(")"}') has different problem:

Yeah, it depends what you put in the raw string.

gaborcsardi avatar Jan 25 '23 23:01 gaborcsardi

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.

hadley avatar Jan 26 '23 13:01 hadley