See example:
df <- data.frame(month=rep(1:3,2),
student=rep(c("Amy", "Bob"), each=3),
A=c(9, 7, 6, 8, 6, 9),
B=c(6, 7, 8, 5, 6, 7))
cnames<-function(){c(month="month",student="student")}
When wrapping cnames()
into c()
the call to tidyr::gather
works:
df2 <- df %>%
gather(variable, value, -c(cnames()))
but it fails when i call it with cnames()
or even (cnames())
only :
df2 <- df %>%
gather(variable, value, -(cnames()))
i.e.
> df2 <- df %>%
+ gather(variable, value, -(cnames()))
Error in -(cnames()) : invalid argument to unary operator
I am guessing this has something to do with NSE but what exactly?