By default, %>% passes the LHS as the 1st argument to the function in RHS. For cor, that is not the correct input. And since it does not have a data argument, you can't use it, unless you use with or within.
In this situation, use %$% operator, also from magrittr. From the docs:
Expose the names in lhs to the rhs expression. This is useful when functions do not have a built-in data argument.
An example:
library(dplyr)
library(magrittr)
mtcars %>%
filter(gear == 4) %$%
cor(x = mpg,
y = disp)