Hi,
Welcome to the RStudio community!
Judging by a similar post it seems this issue is indeed RStudio related. I tested it and it rund fine for me, but I'm on the latest version of RStudio (Version 1.3.1073)
I suggest you update your RStudio (Help -> Check for Updates) and see if the issue persists. Also, to make sure it's RStudio if this fails, try to run the code in plain R to verify.
Hope this helps,
PJ