strs <- c("AB", "CD", NA)
# Use startsWith() to detect a fixed initial substring. Doing so is more readable and more efficient.
grepl("^A", strs) # [1] TRUE FALSE FALSE
startsWith(strs, "A") # [1] TRUE FALSE NA
I would expect that the warning gives enough details to either
- suggest a working solution that considers
NAs the same as grepl (I am not aware of any short in-line way), or
- a warning that
NA will require special treatment.
I fear that this necessary special treatment will be bad for readability, anyway.