我用DBI包中的dbListTables编写了一个函数,抛出一个我无法理解的警告。当我在函数之外运行相同的代码时,我没有收到警告消息。为什么dbListTables在通过函数调用时会给出警告消息? (R DBI)
有关信息,使用的数据库是Microsoft SQL Server。
重复的例子,
library(odbc)
library(DBI)
# dbListTables in a function: gives a warning message
dbListTablesTest <- function(dsn, userName, password){
con <- dbConnect(
odbc::odbc(),
dsn = dsn,
UID = userName,
PWD = password,
Port = 1433,
encoding = "latin1"
)
availableTables <- dbListTables(con)
}
availableTables <-
dbListTablesTest(
dsn = "myDsn"
,userName = myLogin
,password = myPassword
)
# dbListTables not within a function works fine (no warnings)
con2 <- dbConnect(
odbc::odbc(),
dsn = "myDsn",
UID = myLogin,
PWD = myPassword,
Port = 1433,
encoding = "latin1"
)
availableTables <- dbListTables(con2)
(顺便说一句,我知道我应该使用dbDisconnect缩小与它的工作后的连接。但是,这似乎抛出了类似的警告。所以为了简单起见,我已经省略dbDisconnect。)
警告消息
当执行上面的代码时,得到以下的警告MESSA当使用第一个选项时(通过函数),但当我使用第二个选项(没有功能)时我没有得到它。
warning messages from top-level task callback '1'
Warning message:
Could not notify connection observer. trying to get slot "info" from an object of a basic class ("character") with no slots
该警告显然是由dbListTables引起的,因为当我从上述功能中省略该行时它会消失。
我的问题
- 为什么会收到这样的警告消息?
- 更具体地说,为什么我只通过函数调用dbListTables时才得到它?
- 我在做什么错了/我该怎么做才能避免它?
我的会话信息
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=Dutch_Belgium.1252 LC_CTYPE=Dutch_Belgium.1252 LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C LC_TIME=Dutch_Belgium.1252
attached base packages:
[1] stats graphics grDevices utils datasets tools methods base
other attached packages:
[1] DBI_0.7 odbc_1.1.3
loaded via a namespace (and not attached):
[1] bit_1.1-12 compiler_3.4.2 hms_0.3 tibble_1.3.4 Rcpp_0.12.13 bit64_0.9-7 blob_1.1.0 rlang_0.1.2
在此先感谢您的帮助!
我使用'dbGetQuery'得到相同的警告,所以这似乎是一个更广泛的问题。 – JAD