#Create vector of strings
vec <- c("Rose", "Thistle", "Leek", "Shamrock")
#View vector
vec[1] "Rose" "Thistle" "Leek" "Shamrock"
The function stringr::str_detect() detects the presence of a pattern/regular expression within each element of a string vector. It returns a logical vector with TRUE for matches and FALSE otherwise.
Prior to using the function create a vector of strings.
You can specify a string pattern to be used for detection.
The function is case-sensitive. “R” will detect “Rose” but not “shamrock”.
You can use various regular expressions.
You carry out an inverted search (i.e. it returns FALSE if it does match) with the option negate=TRUE.