library(stringr)

sentence <- "This is a (sample) sentence."

uppercase_inside_parentheses <- function(text) {
  result <- str_replace_all(text, "\\((.*?)\\)", function(match) {
    return(paste0("(", toupper(match %>% str_remove("\\(|\\)"))))
  })
  
  return(result)
}

modified_sentence <- uppercase_inside_parentheses(sentence)

print(modified_sentence)
## [1] "This is a (SAMPLE) sentence."
##########################################
library(stringr)

sentences <- c("This is a (sample) sentence.", "Another (example) sentence.")

uppercase_inside_parentheses <- function(text) {
  result <- str_replace_all(text, "\\((.*?)\\)", function(match) {
    return(paste0("(", toupper(match %>% str_remove("\\(|\\)"))))
  })
  
  return(result)
}

modified_sentences <- uppercase_inside_parentheses(sentences)

print(modified_sentences)
## [1] "This is a (SAMPLE) sentence." "Another (EXAMPLE) sentence."