Created
October 2, 2021 13:41
-
-
Save geotheory/b82f26f253a3fd5b695817a0cc31eec5 to your computer and use it in GitHub Desktop.
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
# String in text (vectorised) | |
# A Python-style String in Text operator that ignores case. Either x or pattern must be a single value. Returns a logical value or vector. | |
{\(pattern, x) stringi::stri_detect_regex(x, pattern, case_insensitive = TRUE)} -> `%IN%` | |
# usage | |
'dog' %IN% 'the nice dog said hello' | |
#> [1] TRUE | |
'dog.*said' %IN% 'the nice dog said hello' | |
#> [1] TRUE | |
q = 'dog' | |
vec = c('nice dog', 'nice cat', 'NICE DOG', 'hey duggee') | |
q %IN% vec | |
#> [1] TRUE FALSE TRUE FALSE | |
q = c('dog', 'cat', 'bird', 'mouse') | |
str = 'the cat sat on the mat' | |
q %IN% str | |
#> [1] FALSE TRUE FALSE FALSE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment