patternapply

Iteratively try patterns against a character vector.
git clone https://git.eamoncaddigan.net/patternapply.git
Log | Files | Refs | README | LICENSE

filterPatternMatches.R (837B)


      1 #' Filter out all of the records that match an existing pattern.
      2 #' 
      3 #' @param X A character vector where matches are sought.
      4 #' @param patterns A vector of regular expression patterns.
      5 #'   
      6 #' @return The subset of \code{X} that did not match any of the regexes in 
      7 #'   \code{patterns}
      8 #'   
      9 #' @details This is meant to be useful when developing a vector of regexes to 
     10 #'   apply to text. Regular expressions can be appended to \code{patterns}
     11 #'   interactively until the edge cases are all covered, and then
     12 #'   \code{patternapply()} can be deployed to extract data.
     13 #' @export
     14 filterPatternMatches <- function(X, patterns) {
     15   unmatchedRecords <- X
     16   for (pattern in patterns) {
     17     unmatchedRecords <- subset(unmatchedRecords, 
     18                                !grepl(pattern, unmatchedRecords))
     19   }
     20   return(unmatchedRecords)
     21 }