I am trying to get the number of open brackets in a character string in R. I am using the str_count function from the stringr package
str_count
stringr
( is a special character. You need to escape it:
(
str_count(s,"\\(") # [1] 3
Alternatively, given that you're using stringr, you can use the coll function:
coll
str_count(s,coll("(")) # [1] 3