0

In R left-to-right associativity is the norm, for instance:

5 - 3 - 1 == (5 - 3) - 1 # TRUE
5 - 3 - 1 == 5 - (3 - 1) # FALSE

Is there a way to get right-to-left associativity instead, for a given operator?

Note that I am aware of this post; however it does not answer my question above, here is why:

library(backpipe)
"%diff%" <- function(x, y) y - x
"%-%" <- backpipe("%diff%")
5 %-% 3 %-% 1 == (5 %-% 3) %-% 1 # TRUE
5 %-% 3 %-% 1 == 5 %-% (3 %-% 1) # FALSE
Community
  • 1
  • 1
polmath
  • 335
  • 2
  • 13
  • why do you want this – MichaelChirico Aug 30 '16 at 20:23
  • I have an operator `%->%`, which is actually mathematically associative; but the structure of the objects it acts upon makes it much more efficient to evaluate `a %->% (b %->% c)` rather than `(a %->% b) %->% c`. And I want to avoid too many parentheses... – polmath Aug 30 '16 at 20:35

0 Answers0