Does this happen if you try to run the same script outside of the the RStudio IDE?
For clarification about the difference between R and RStudio, I made this little FAQ: