How to determine the priority of the operator% foo% and% bar%?
You can not. R does not allow you to set the priority of user infix operators. Custom infix operators have default priority rules, which means they will be evaluated from left to right.
One of the reasons for this restriction is that it would be extremely difficult to limit the implementation and maintenance of a set of bias rules for infix operators. Imagine that you downloaded the R package, which comes with some infix user operations. Then it will be necessary to determine the relationship of the infix operators from the package with the %foo% and %bar% that you created. This will quickly become a serious burden.
As an example, suppose the packet contains the infix operator %P1IF% , and the second packet contains the infix operator %P2IF% . Each package determined that its infix operator should have the highest priority. If you were to download both packages one and two, then the following expression would be undefined:
v1 %P1IF% v2 %P2IF% v3 (v1 %P1IF% v2) %P2IF% v3
No matter what priority may result from one of the two packages, it may be incorrect.
source share