How can I determine the operator precedence of %foo% and %bar%?
You can't. R doesn't allow you to set the precedence of custom infix operators. User-defined infix operators have the default precedence rules which means they will be evaluated from left to right.
One reason for this limitation is that it would be extremely difficult and limiting to implement and maintain a set of precendence rules for infix operators. Imagine that you loaded an R package which comes with some custom infix operators. Then the relationship of the infix operators from the package to the %foo%
and %bar%
which you created would need to be defined. This will quickly become a serious burden.
As an example, imagine that package one contains infix operator %P1IF%
and package two contains infix operator %P2IF%
. Each package has defined that its infix operator should have the highest precedence. If you were to load both package one and two, then the following expression would be undefined:
v1 %P1IF% v2 %P2IF% v3
(v1 %P1IF% v2) %P2IF% v3 # package 2 doesn't expect this
v1 %P1IF% (v2 %P2IF% v3) # package 1 doesn't expect this
Regardless of what the precedence might be the result for one of the two packages might be incorrect.