我是新来的R
我正在尝试使用 RStudio 连接到 PostgreSQL。
我已经安装了RPostgreSQL
并尝试了以下代码:
> library("DBI", lib.loc="~/R/win-library/3.2")
> library("RPostgreSQL", lib.loc="~/R/win-library/3.2")
> con <- dbConnect(dbDriver("PostgreSQL"), dbname="Delta", user="postgres")
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect postgres@local on dbname "Delta"
由于某种原因我无法连接到数据库。我想解决这个问题很长时间,但不知道如何解决。
我对这个问题的解决方案是使用RPostgres
https://github.com/rstats-db/RPostgres.
假设您有连接url
,以下代码将起作用:
library(DBI)
library(RPostgres)
con <- dbConnect(RPostgres::Postgres(),
host = url$host,
port = url$port,
dbname = url$dbname,
user = url$user,
password = url$password
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)