I would like to write a function that takes quosure as an argument, adds -
to quosure and passes this value to gather
, for example:
library(tidyverse)
my_gather <- function(d, not.columns) {
dg <- tidyr::gather(d, key = k, value = v, .dots = -!!!not.columns)
dg
}
de <- my_gather(mtcars, not.columns = quos(mpg, cyl, disp))
> Error in `-`(~mpg, ~cyl, ~disp) : operator needs one or two arguments
This is clear because I need to add every quosure element with -
, rather than add all quosure with -
. But in my work, creating this quosure will not be easy in form quos(-mpg, -cyl, -disp)
- so how can I change quos(mpg, cyl, disp)
to add -
?
I would like to see a result that is identical gather(mtcars, key = k, value = v, -mpg, -cyl, -disp)
, the first 3 lines of which are equal
mpg cyl disp k v
1 21.0 6 160 hp 110
2 21.0 6 160 hp 110
3 22.8 4 108 hp 93
There is a similar question here, but it does not answer and does not seem to address the problem quos()
, not quo()
.