Does R 4.0.0. make it possible to define foo"(...)" operators, similar to the newly introduced r"(...)" syntax?
Asked Answered
L

1

6

R 4.0.0 brings in a new syntax for raw strings:

r"(raw string here can contain anything except the closing sequence)"

But this same construct in R 3.x.x produced a syntax error:

Error: unexpected string constant in "r"(asdasd)""

Does it mean that the interpreter was changed in R 4.0.0. ?
And if so - does R 4.0.0. provide a mechanism to define custom functions like foo"()" ?

Ludovick answered 24/4, 2020 at 11:43 Comment(0)
P
4

No, that's not possible at the moment (nor would I anticipate it becoming possible anytime soon).

Here's the NEWS item:

There is a new syntax for specifying raw character constants similar to the one used in C++: r"(...)" with ... any character sequence not containing the sequence )". This makes it easier to write strings that contain backslashes or both single and double quotes. For more details see ?Quotes.

https://cran.r-project.org/doc/manuals/r-devel/NEWS.html

Then from ?Quotes:

Raw character constants are also available using a syntax similar to the one used in C++: r"(...)" with ... any character sequence, except that it must not contain the closing sequence )". The delimiter pairs [] and {} can also be used, and R can be used in place of r. For additional flexibility, a number of dashes can be placed between the opening quote and the opening delimiter, as long as the same number of dashes appear between the closing delimiter and the closing quote.

https://github.com/wch/r-source/blob/trunk/src/library/base/man/Quotes.Rd

Here's the (git mirror of the SVN patch of the) commit where this functionality was added:

https://github.com/wch/r-source/commit/8b0e58041120ddd56cd3bb0442ebc00a3ab67ebc

Pebrook answered 24/4, 2020 at 11:52 Comment(1)
Thanks and +1, specially for including the commit. Based on the code there it seems like indeed the parser was adjusted (src/main/gram), but only in a way that allows for r or R to be used before the quote.Charitycharivari

© 2022 - 2024 — McMap. All rights reserved.