r - postgresqlNewConnection(drv, ...) 中的错误:用户参数不能为 NULL
问题描述
嘿,我正在尝试将 R 连接到 sql 数据库,但出现此错误。以下是代码。你知道如何修复这个错误吗?太感谢了。
对不起,我不能在这里发布用户名和密码信息。但我确信用户名和密码信息是正确的。
library(DBI)
library(RPostgreSQL)
library(ggplot2)
usr <- {"######"}
pw <- {"######"}
dbs <- list()
dbs$r2day <-
list(
dbname = "gp_adw",
host = "csia4gpm01",
port = 5432,
user = usr,
password = pw
)
sql_q <- function(query = "", db = "")
{
# strip off db info from the dbs list
db_info <- dbs[[db]]
# specify driver type
drv <- dbDriver("PostgreSQL")
# connet db with db_info
con <- dbConnect(
drv,
dbname = db_info$dbname,
host = db_info$host,
port = db_info$port,
user = db_info$user,
password = db_info$password
)
# submit query and bring result back in R
df_postgres <- dbGetQuery(con, query)
# disconnect the db and unload the driver
dbDisconnect(con)
dbUnloadDriver(drv)
# return the r object
df_postgres
}
alpha <- sql_q(query = "select * from comscore.mm200_pattern_parentage_222m limit 100", db = "gp_adw")
错误是
Error in postgresqlNewConnection(drv, ...) : user argument cannot be NULL
解决方案
推荐阅读
- c - lang-c 使用嵌套的for循环和函数打印两个中间有空格的金字塔?
- python - Python 在 C++ 中崛起 ** 运算符
- java - 为什么我的android应用程序循环时不会增加时间?
- c++ - 令人沮丧的数学问题,结果不如预期(EDQ)
- tomcat - 使用 Pentaho 用户控制台 9.0 生成 PDF 报告
- python - 使用上下文管理器重构 if-else 块 python?
- python - seaborn点图可视化
- python - 如何运行模型而无需再次运行训练数据
- firebase - getter 'uid' 被调用为 null - 但只有一半的时间
- r - 结合图例填充和颜色ggplot只给出一个图例