I have run into a problem when trying to use \Sexpr{} in Sweave files in RStudio Version 2023.12.0+369 (2023.12.0+369).
The problem is best demonstrated in the image below. I have noticed that when I use square brackets within an \Sexpr{} tag then all of the text (not code) after that tag is interpreted by RStudio as code, and not text. This seems like a bug in the IDE to me. And I will note that this was not happening to me a few months ago. So it seems that in an update of RStudio or maybe knitr something appears to have changed.