Checking if string is in uppercase in R
If you prefer to live in a tidyr
universe, here's the version using stringr
:
library(stringr)
str_detect(s, "^[:upper:]+$")
Why not just test if the word is identical to itself when converted to upper case with the "toupper" function?
word1 <- "TEST"
word1 == toupper(word1)
will be TRUE
You can use the ^
and $
patterns to match the beginning and end of the string
grepl("^[[:upper:]]+$", s)