str_equal: Determine if two strings are equivalent

View source: R/equal.R

str_equalR Documentation

Determine if two strings are equivalent

Description

This uses Unicode canonicalisation rules, and optionally ignores case.

Usage

str_equal(x, y, locale = "en", ignore_case = FALSE, ...)

Arguments

x, y

A pair of character vectors.

locale

Locale to use for comparisons. See stringi::stri_locale_list() for all possible options. Defaults to "en" (English) to ensure that default behaviour is consistent across platforms.

ignore_case

Ignore case when comparing strings?

...

Other options used to control collation. Passed on to stringi::stri_opts_collator().

Value

An logical vector the same length as x/y.

See Also

stringi::stri_cmp_equiv() for the underlying implementation.

Examples

# These two strings encode "a" with an accent in two different ways
a1 <- "\u00e1"
a2 <- "a\u0301"
c(a1, a2)

a1 == a2
str_equal(a1, a2)

# ohm and omega use different code points but should always be treated
# as equal
ohm <- "\u2126"
omega <- "\u03A9"
c(ohm, omega)

ohm == omega
str_equal(ohm, omega)

stringr documentation built on Nov. 15, 2023, 1:08 a.m.