can I be sure that I always get "<-" operator in syntax tree
Let’s see …
> quote(b -> a)
a <- b
> identical(quote(b -> a), quote(a <- b))
[1] TRUE
So yes, the ->
assignment is always parsed as <-
(the same is not true when invoking ->
as a function name!1).
Your first display is the other way round because of parse
’s keep.source
argument:
> parse(text = 'b -> a')
expression(b -> a)
> parse(text = 'b -> a', keep.source = FALSE)
expression(a <- b)
1 Invoking <-
as a function is the same as using it as an operator:
> quote(`<-`(a, b))
a <- b
> identical(quote(a <- b), quote(`<-`(a, b)))
[1] TRUE
However, there is no ->
function (although you can define one), and writing b -> a
never calls a ->
function, it always gets parsed as a <- b
, which, in turn, invokes the <-
function or primitive.