I expected to see only CYL after dropping vars that contain "ar". But the outcome I get contains both CARB (contain "ar") and all other variables. Am I missing anything here
^c means the first character has to be c. Then (?!.*ar) is a negative lookahead that matches only strings that don't contain ar anywhere after the initial c.
However, the above code results in an "invalid regular expression" error.
If this were one of the grep functions, you could avoid this with a perl=TRUE argument, but that doesn't appear to be available in the standard tidyselect helpers (but see update below; it's now available in the development version). Based on this SO answer, here's a select helper that uses perl regular expressions:
matches2 <- function (match, ignore.case = TRUE, vars = current_vars()) {
tidyselect:::grep_vars(match, vars, ignore.case=ignore.case, perl=TRUE)
}
Thanks @martin.R. This answers the question, but I wanted to do it in one stage because the selection criteria is more than the simple example I have here.