In R, how can I determine the operator precedence of user defined infix operators? -


suppose have 2 custom infix operators in r: %foo% , %bar%.

i have expressions use both operators, such as:

x %foo% y %bar% z 

how can determine operator precedence of %foo% , %bar%?

how can change precedence that, example, %bar% executes before %foo%? in example above same as:

x %foo% (y %bar% z) 

i don't think explicitly documented, implicit in r language documentation infix operators of equal precedence , executed left right. can demonstrated follows:

`%foo%` <- `+` `%bar%` <- `*` 1 %bar% 2 %foo% 3 #5 1 %foo% 2 %bar% 3 #9 

the option can think of redefine 1 of existing operators wanted. however, have repercussions might want limit within function.

it's worth noting using substitute not change operator precedence set when expression first written:

eval(substitute(2 + 2 * 3, list(`+` = `*`, `*` = `+`))) #10 2 * 2 + 3 #7 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -