I have data frame as follows
df = data.frame(a=c(1:10), b=c(2:11), c=c(2:13))
The user specified a vector of variable names as characters
user_cols = c('a', 'b')
I want to take the vector and use select() to keep the variables being reference by the vector. The following code would work
df2 = df %>%
select(!!!syms(user_cols))
However, if I want to drop these variable rather than keep these variables, adding a negation (-) directly to the syntax would NOT work:
df2 = df %>%
select(-!!!syms(user_cols)) #Adding negation '-' hoping to de-select
Is there a good way of achieving this dropping operation in dplyr?