I'm trying to use objects for the column name and variables in dplyr filter? I've read a few posts, but can't get any of them to work (How do you rename a column with dplyr using a character object). It works if I name the column and variables, but not if I preassign them, as below. I want to be able to dynamically name the column and variables.
col <- "Species"
vars <- c("setosa", "versicolor")
r <- iris %>%
filter(col %in% vars)
r <- iris %>%
filter(Species %in% c("setosa", "versicolor"))