My solution was to use the select ability to use column positions. The as.name solution does not seem to work for some of my columns.
select(df, which(names(df) %in% myvar))
or even more succinctly, if already in the pipe:
df %>% select(which(names(.) %in% myvar))
Although this uses select , in my opinion, it does not rely on NSE.
Please note that if there are no matches, all columns will be deleted without errors or warnings.
source share