Skip to content

Commit 98b4fa8

Browse files
committed
Respect modifiers of named vectors
Fixes #207
1 parent 826d4cf commit 98b4fa8

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# stringr 1.3.0.9000
22

3+
* `str_replace_all()` with a named vector now respects modifier functions (#207)
4+
35
* `str_trunc()` is once again vectorised correctly (#203, @austin3dickey).
46

57
# stringr 1.3.0

R/replace.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ str_replace_all <- function(string, pattern, replacement) {
7979
if (!is.null(names(pattern))) {
8080
vec <- FALSE
8181
replacement <- unname(pattern)
82-
pattern <- names(pattern)
82+
pattern[] <- names(pattern)
8383
} else {
8484
vec <- TRUE
8585
}

tests/testthat/test-replace.r

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ test_that("can replace multiple matches", {
4040
expect_equal(y, c("11", "22"))
4141
})
4242

43+
test_that("multiple matches respects class", {
44+
x <- c("x", "y")
45+
y <- str_replace_all(x, regex(c("X" = "a"), ignore_case = TRUE))
46+
expect_equal(y, c("a", "y"))
47+
})
48+
4349
test_that("replacement must be a string", {
4450
expect_error(str_replace("x", "x", 1), "must be a character vector")
4551
})

0 commit comments

Comments
 (0)