I'm trying to drop columns from the columns to be gathered using the gather()
function in the R package tidyr
.
This works fine when I specify what columns I want to gather (here, I'm gathering the mpg
, cyl
, and disp
columns into variable
and val
columns:
library(tidyverse)
mtcars %>%
select_("mpg", "cyl", "disp") %>%
gather_("variable", "val", gather_cols = c("mpg", "cyl", "disp"))
Let's say I had four variables, and instead of specifying which to gather, I wanted to specify which to drop (hp
in this next case). This, probably obviously, doesn't work:
mtcars %>%
select_("mpg", "cyl", "disp", "hp") %>%
gather_("var", "val", gather_cols = c(-"hp"))
The suggestion to use one_of
- as in the answer to this question - doesn't seem to work. In a now-closed GitHub issue for tidyr
, it is suggested to use dplyr::select_vars()
, but this doesn't seem to work, either.
How could this - specifying which columns to drop with standard evaluation using gather()
?