Skip to content
Prev 58333 / 63424 Next

detect ->

On Mon, Apr 13, 2020 at 9:23 AM Gabriel Becker <gabembecker at gmail.com> wrote:
[...]
Well, especially considering R's news raw strings with user defined
delimiters, regular expressions are not the best here, I think. OTOH
the source references do keep the right assignment. So if you can
re-parse the data, you can detect them:

? x <- parse(text = "A -> B", keep.source=FALSE)
? x
expression(B <- A)

? x <- parse(text = "A -> B")
? x
expression(A -> B)

? getParseData(x)
  line1 col1 line2 col2 id parent        token terminal text
7     1    1     1    6  7      0         expr    FALSE
1     1    1     1    1  1      3       SYMBOL     TRUE    A
3     1    1     1    1  3      7         expr    FALSE
2     1    3     1    4  2      7 RIGHT_ASSIGN     TRUE   ->
4     1    6     1    6  4      6       SYMBOL     TRUE    B
6     1    6     1    6  6      7         expr    FALSE

Gabor

[...]