Here are examples of searching with and without case insensitivity using the tag (?i).
library(dplyr)
library(stringr)
work_sector_new <- data.frame(work_sector=c("a doctor", "The Doctor", "mechanic",
"doctorate"))
#Case sensitive version
work_sector_new %>%
mutate(
label = case_when(
str_detect(work_sector, "doctor") ~ "23"))
work_sector label
1 a doctor 23
2 The Doctor <NA>
3 mechanic <NA>
4 doctorate 23
#Case insensitive version
work_sector_new %>%
mutate(
label = case_when(
str_detect(work_sector, "(?i)doctor") ~ "23"))
work_sector label
1 a doctor 23
2 The Doctor 23
3 mechanic <NA>
4 doctorate 23