R/tidyverse_extensions.R

Defines functions match2

Documented in match2

#' Match Based on Two Strings
#'
#' @param match1 First string
#' @param match2 Second string
#'
#' @return Indices to be used by \code{dplyr::select} etc.
#' @export
#'
#' @examples
#' library(dplyr)
#' # Select columns containing a and r
#' mtcars %>% select_at(vars(match2("r", "a")))
#'
match2 <- function(match1, match2) {
  intersect(tidyselect:::grep_vars(needle = match1, haystack = tidyselect::peek_vars()),
            tidyselect:::grep_vars(needle = match2, haystack = tidyselect::peek_vars()))
}
osorensen/mytools documentation built on May 3, 2019, 5:47 p.m.