patternapply

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

test_generics.R (725B)


      1 library(patternapply)
      2 context("Using generics")
      3 
      4 inputStrings <- paste(letters, seq_along(letters), sep = "_")
      5 patterns <- c("([[:digit:]]{2})",
      6               "([[:alpha:]])")
      7 replacements <- list(c("\\1", "1"),
      8                      c("\\1", "2"))
      9 patternapplyResult <- patternapply(inputStrings, patterns, replacements)
     10 patternapplyResultMatrix <- as.matrix(patternapplyResult)
     11 patternapplyResultDF <- as.data.frame(patternapplyResult)
     12 
     13 test_that("Converting to matrix works", {
     14   expect_is(patternapplyResultMatrix, "matrix")
     15   expect_equal(ncol(patternapplyResultMatrix), 2)
     16 })
     17 
     18 test_that("Converting to data.frame works", {
     19   expect_is(patternapplyResultDF, "data.frame")
     20   expect_equal(ncol(patternapplyResultDF), 2)
     21 })