To clarify, R is the language, and RStudio is just the IDE (see FAQ below for disambiguation). Since this question isn't about the IDE itself, I'm going to move it to #general.
What you're describing sounds like a good use-case for grepl() or a similar string-matching function which:
search for matches to argument pattern within each element of a character vector
str_detect() from the stringr package does ~ the same thing.
The chapter on strings from R for Data Science might be worth looking at.