Is the %>% pipe operator always feeding the left side (LHS) to the first argument of the right side (RHS)? Even if the first argument is again specified in the RHS call?
Not. You yourself noticed this exception: if the right side is using . , the first argument of the left side is not supplied. You need to transfer it manually.
However, this does not happen in your case, because you are not using . yourself, you use it inside the expression. To avoid using the left side as the first argument, you also need to use curly braces:
iris %>% {cor(x = .$Sepal.Length, y = .$Sepal.Width)}
Or:
iris %$% cor(x = Sepal.Length, y = Sepal.Width)
- in the end, why %$% exists, unlike %>% .
But compare:
iris %>% lm(Sepal.Width ~ Sepal.Length, data = .)
The left expression was explicitly passed here as the data argument in lm . By doing so, we prevent it from being passed as the first argument to lm .
source share