Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"()" ?

like image 653
Karolis Koncevičius Avatar asked Apr 24 '20 11:04

Karolis Koncevičius


1 Answers

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

like image 133
MichaelChirico Avatar answered Oct 16 '22 23:10

MichaelChirico