Using the rlang package, I wonder what is the difference between sym()
and parse_expr()
. Consider for example the following expressions:
ex1 = sym('a')
ex2 = parse_expr('a')
They both return
a
identical(ex1, ex2)
[1] TRUE
Suppose now I need a quosure:
ex3 = quo(!!sym('a'))
ex4 = quo(!!parse_expr('a'))
In both case, the result is:
<quosure>
expr: ^a
env: global
identical(ex3, ex4)
[1] TRUE
However, the two following are not the same for some reasons.
ex5 = quo(!!sym('a - b'))
ex6 = quo(!!parse_expr('a - b'))
Apparently they are identical as both return:
<quosure>
expr: ^a - b
env: global
Yet,
identical(ex5, ex6)
[1] FALSE
So, my question is, what are the differences between sym()
and parse_expr()
?
What does one do that the other cannot? And why is ex5
apparently similar to ex6
, but identical(ex5, ex6)
returns FALSE?