I am trying to figure out why the tee operator, %T>%, does not work when I pass the data to a ggplot command.
This works fine
library(ggplot2)
library(dp
Either
mtcars %T>%
{print(ggplot(.) + geom_point(aes(cyl, mpg)))} %>%
{ggplot(.) + geom_point(aes(mpg, cyl))}
or abandon the %T>%
operator and use an ordinary pipe with the "%>T%" operation made explicit as a new function as suggested in this answer
techo <- function(x){
print(x)
x
}
mtcars %>%
{techo( ggplot(.) + geom_point(aes(cyl, mpg)) )} %>%
{ggplot(.) + geom_point(aes(mpg, cyl))}
As TFlick noted, the reason the %T>% operator doesn't work here is because of the precedence of operations: %any%
is done before +
.