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
If you want to do it in base R you can split into a vector of individual characters and count the "(" directly (without representing it as a regular expression):
"("
> s<- "(hi),(bye),(hi)" > chars <- unlist(strsplit(s,"")) > length(chars[chars == "("]) [1] 3