Although I accepted the @ C-Z_ answer, I want to add another to provide context. Thanks @rawr for pointing me to ?Syntax .
In general, %>% is considered an operator, for example, %in% , and as such it must obey the order of operations. On the Syntax help page, this corresponds to the %any% operator (i.e., any infix operator), since users can define them as they wish. As this happens, this means that %>% triggered before any logical operator, as well as before arithmetic operators (for example, * and \ ). As a result, if you are naive, like me, that the left side of %>% ends before the next step in the chain, you may get some surprises. For instance:
3+2 %>% '*'(4) %>% `/`(2)
Does not 3+2=5, 5*4= 20, 20/2=10
instead, it does 2*4/2=4, 4+3=7 , since %>% takes precedence over + .
If you use functions in the magrittr package, for example:
add(3,2) %>% multiply_by(4) %>% divide_by(2)
You get 10 as expected. Placing brackets around 3+2 will also give you 10 .
In my initial examples, logical operators such as ! , have a lower priority than %>% , so they act last after the amount has competed.
The moral of the story: be careful when mixing %>% with other operators.