Skip to content

Commit f482fb0

Browse files
committed
Add locale and ignore_case arguments to str_unique()
For consistency with str_equal()
1 parent b96a417 commit f482fb0

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

R/unique.R

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,27 @@
44
#' how duplication is measured.
55
#'
66
#' @inheritParams str_detect
7-
#' @param ... Other options used to control matching behavior between duplicate
8-
#' strings. Passed on to [stringi::stri_opts_collator()].
7+
#' @inheritParams str_equal
98
#' @return A character vector, usually shorter than `string`.
109
#' @seealso [unique()], [stringi::stri_unique()] which this function wraps.
1110
#' @examples
1211
#' str_unique(c("a", "b", "c", "b", "a"))
1312
#'
13+
#' str_unique(c("a", "b", "c", "B", "A"))
14+
#' str_unique(c("a", "b", "c", "B", "A"), ignore_case = TRUE)
15+
#'
1416
#' # Use ... to pass additional arguments to stri_unique()
1517
#' str_unique(c("motley", "mötley", "pinguino", "pingüino"))
1618
#' str_unique(c("motley", "mötley", "pinguino", "pingüino"), strength = 1)
1719
#' @export
18-
str_unique <- function(string, ...) {
19-
stri_unique(string, opts_collator = stri_opts_collator(...))
20+
str_unique <- function(string, locale = "en", ignore_case = FALSE, ...) {
21+
check_string(locale)
22+
check_bool(ignore_case)
23+
24+
opts <- str_opts_collator(
25+
locale = locale,
26+
ignore_case = ignore_case,
27+
...
28+
)
29+
stri_unique(string, opts_collator = opts)
2030
}

man/str_unique.Rd

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-unique.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ test_that("unique values returned for strings with duplicate values", {
22
expect_equal(str_unique(c("a", "a", "a")), "a")
33
expect_equal(str_unique(c(NA, NA)), NA_character_)
44
})
5+
6+
test_that("can ignore case", {
7+
expect_equal(str_unique(c("a", "A"), ignore_case = TRUE), "a")
8+
})

0 commit comments

Comments
 (0)