Does this work for you in R, but not in RStudio? (see FAQ below for disambiguation)
If you're on a Mac, this guide can be helpful for getting rJava running right: