grapes-contains_word-grapes: check whether a character string contains another as a word

Description Usage Arguments Examples

Description

Looks for a string appearing on its own. This is needed e.g. when checking whether the replies to a mmc item, stored as a comma-separated list from 1 to 12 contain option 1 - you wouldn't want to get a hit for 11 and 12. Only works for search terms containing alphanumeric characters. Just a simple shorthand so that inexperienced R users don't have to use somewhat complex functions such as grepl() and stringr::str_detect().

Usage

1
haystack %contains_word% needle

Arguments

haystack

string in which you search

needle

string to search for

Examples

1
2
3
"1, 3, 4" %contains_word% "1" # TRUE
"1, 3, 4" %contains_word% 1 # TRUE unlike str_detect casts all needles as characters
"12, 14, 17" %contains_word% "1" # FALSE even though 12 contains 1

grebbel/formr_test documentation built on May 17, 2019, 8:34 a.m.