1

I'm trying to access a PostgreSQL database through R. I tried the following code:

   library(RPostgreSQL)
   library(DBI)

   drv <- dbDriver("PostgreSQL")

   con = dbConnect(drv, #constructs SQL driver
                   host = MyHost, 
                   port = MyPort,
                   dbname = MyDbname,
                   user = MyUser,
                   password = pw)

I already have PostgreSQL installed on my computer. With all my credentials being correct, I still get this Error:

 Error in postgresqlNewConnection(drv, ...) : 
     RS-DBI driver: (could not connect [MyUser]@[MyHost] on MyDbname 

any ideas what causes the problem? The same problem here has no solution yet. Thanks for your help

   > sessionInfo()
   R version 3.3.1 (2016-06-21)
   Platform: x86_64-apple-darwin13.4.0 (64-bit)
   Running under: OS X 10.11.6 (El Capitan)

Kasia

Community
  • 1
  • 1
Kasia Kulma
  • 1,683
  • 1
  • 14
  • 39

1 Answers1

3

At the end, I managed to connect to the database with RPosgres package

install.packages("devtools") and load them
devtools::install_github("RcppCore/Rcpp")
devtools::install_github("rstats-db/DBI")
devtools::install_github("rstats-db/RPostgres")


con <- dbConnect(RPostgres::Postgres(),
             host = MyHost,
             port = MyPort,
             dbname = MyDbname,
             user = MyUser,
             password = pw)


res <- dbSendQuery(con, "SELECT * FROM orders LIMIT 10")
dbFetch(res)
dbClearResult(res)
Kasia Kulma
  • 1,683
  • 1
  • 14
  • 39