I would like to use str_extract_all to extract specific text strings from many columns of a spreadsheet containing error descriptions. A sample list:
fire_match <- c('fire', 'burned', 'burnt', 'burn', 'injured', 'injury', 'hurt', 'dangerous',
'accident', 'collided', 'collide', 'crashed', 'crash', 'smolder', 'flame', 'melting',
'melted', 'melt', 'danger')
My code technically does what it is supposed to do, but I am also extracting (for example) 'fire' from 'misfire'. This is incorrect. I am also having difficulty extracting results that are not case sensitive.
This is a direct example of what is getting me 90% of the way there:
fire$Cause.Trigger <- str_extract_all(CAUSE_TEXT, paste(fire_match, collapse="|") )
My desired result is:
CAUSE_TEXT <- c("something caught fire", "something misfired",
"something caught Fire", "Injury occurred")
- something caught fire -> fire
- something misfired -> N/A
- something caught Fire -> fire
- an Injury occurred -> injury