[Rd] Operator precedence of =, <- and ?

Konrad Rudolph konr@d@rudo|ph @end|ng |rom gm@||@com
Fri Jan 10 11:59:16 CET 2020

The documentation (help("Syntax")) gives the operator precedence of the
assignment operators and help, from highest to lowest, as:

       ‘<- <<-’           assignment (right to left)
       ‘=’                assignment (right to left)
       ‘?’                help (unary and binary)

If I understand correctly this implies that `a = b ? c` and `a <- b ? c`
should parse identically. Or, if using the unary version, `?a = b` and `?a
<- b` should parse identically.

However, as noted by Antoine Fabri on Stack Overflow [1], they have
different parses (on R 3.5.3 and 3.6.1, at least), which puts the
precedence of `?` *between* that of `<-` and `=`. In fact, src/main/gram.y
[2] appears to show the same precedence table as the documentation;
presumably the parser at some point rewrites the parse tree manually.

At any rate, should this be fixed in the documentation? Or is the
documentation “correct”, and there’s a bug in the parser (in some versions
of R)?

[1] <
[2] <

Konrad Rudolph

	[[alternative HTML version deleted]]

More information about the R-devel mailing list