forked from tidyverse/stringr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vectorise pattern in str_detect. Add fixed and ignore.case modifiers
- Loading branch information
Showing
21 changed files
with
166 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# General wrapper around sub, gsub, regexpr, gregexpr, grepl. | ||
# Vectorises with pattern and replacement, and uses fixed and ignored.case | ||
# attributes. | ||
re_vectorise <- function(f, string, pattern, ...) { | ||
f <- match.fun(f) | ||
if (length(pattern) == 1) { | ||
f(pattern, string, | ||
fixed = is.fixed(pattern), ignore.case = case.ignored(pattern)) | ||
} else { | ||
unname(mapply(f, pattern, string, MoreArgs = | ||
list(fixed = is.fixed(pattern), ignore.case = case.ignored(pattern)))) | ||
} | ||
|
||
# Need tests for fixed and ignore.case ! | ||
|
||
|
||
} | ||
|
||
# Check if a set of vectors is recyclable. | ||
# Ignores zero length vectors. Trivially TRUE if all inputs are zero length. | ||
recyclable <- function(...) { | ||
lengths <- vapply(list(...), length, 1) | ||
|
||
lengths <- lengths[lengths != 0] | ||
if (length(lengths) == 0) return(TRUE) | ||
|
||
all(max(lengths) %% lengths == 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
* add examples to str_replace and str_match | ||
|
||
* vectorise with respect to pattern | ||
* implement fixed and ignore.case functions | ||
* check that str_locate, str_extract, str_match, str_replace and str_split all | ||
use new vectorisation and modifier strategy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
library(testthat) | ||
library_if_available(stringr) | ||
|
||
context("String and pattern checks") | ||
|
||
test_that("string is atomic", { | ||
expect_that(check_string(list()), throws_error("must be an atomic")) | ||
}) | ||
|
||
test_that("pattern is a string", { | ||
expect_that(check_pattern(1), throws_error("must be a character vector")) | ||
}) | ||
|
||
test_that("error when string and pattern lengths incompatible", { | ||
expect_that(check_pattern(letters, "a"), equals(letters)) | ||
expect_that(check_pattern("a", letters), equals("a")) | ||
|
||
expect_that(check_pattern(c("a", "b", "c"), c("a", "b")), | ||
throws_error("not compatible")) | ||
expect_that(check_pattern(c("a", "b"), c("a", "b", "c")), | ||
throws_error("not compatible")) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
\name{ignore.case} | ||
\alias{ignore.case} | ||
\title{Ignore case of match.} | ||
\usage{ignore.case(string)} | ||
|
||
\description{ | ||
Ignore case of match. | ||
} | ||
|
||
\details{ | ||
This function specifies that a pattern should ignore the case of | ||
matches. | ||
} | ||
\keyword{character} | ||
\arguments{ | ||
\item{string}{pattern for which to ignore case} | ||
} | ||
\examples{pattern <- "a.b" | ||
strings <- c("ABB", "aaB", "aab") | ||
str_detect(strings, pattern) | ||
str_detect(strings, ignore.case(pattern))} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters