For a while now I have been contemplating pulling data from our postgreSQL db directly from R, but just never actually pulled the trigger until today. What I found was that it was a lot easier than I ever could have imagined. My laptop was already on the VPN, so I decided to try it locally before deploying our R studio server. After a bit of researching, I decided to use the the RPostgreSQL CRAN package. It literally only takes two lines of code and you are ready to go.
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="database", host="", port="", user="", password="")
The first line installs the driver, in my case a postgreSQL driver, the second line actually connects you to your database. All you have to do is input the name of the db, host, port, username, and password. After that, you ready to query!
ba <- dbGetQuery(con,"select * from badass limit 100")