library(stringr)
uppers <- "\\b[:upper:]+\\b"
text <- "Is there a way to count the UPPERCASE words in a dataset? So far, I can only count the number of UPPERCASE characters but not words. Can someone shed some light on this?"
str_count(text,uppers)
#> [1] 3