I've experienced this a couple of times as well. As I recall, it usually happens when the horizontal scroll bar appears. This happens when you have long lines of code that extend off to the right of the viewing pane.
I don't know if there's a setting in RStudio to prevent that, or if it's just a frustrating user experience thing. I try to circumvent it by writing more line breaks in my code (as a rule, if my code extends more than 80 characters on a line, I try to break it into multiple lines)