r - 使用 RSQLite 在 R 中加载 SQLite 表

标签 r sqlite rsqlite r-dbi

我有这个函数用于加载 SQLite 表

sqLiteConnect <- function(database, table) {
  library(DBI)
  library(RSQLite)
  con <- dbConnect("SQLite", dbname = database)
  query <- dbSendQuery(con, paste("SELECT * FROM ", table, ";", sep="")) 
  result <- fetch(query, n = -1, encoding="utf-8")
  dbClearResult(query)
  dbDisconnect(con)
  return(result)
}

但现在它接缝时会产生错误

album <- sqLiteConnect("~/Downloads/ChinookDatabase1.3_Sqlite/Chinook_Sqlite.sqlite","Album")

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘dbConnect’ for signature ‘"character"’
Called from: stop(gettextf("unable to find an inherited method for function %s for signature %s", 
    sQuote(fdef@generic), sQuote(cnames)), domain = NA)

(我从 here 下载了数据库)

这是错误还是我的功能有问题?

 sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] graphics  grDevices utils     datasets  stats     methods   base     

other attached packages:
[1] ggplot2_1.0.0 igraph_0.7.1  RSQLite_1.0.0 DBI_0.3.1    

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 digest_0.6.4     grid_3.1.2       gtable_0.1.2    
 [5] MASS_7.3-35      munsell_0.4.2    plyr_1.8.1       proto_0.3-10    
 [9] Rcpp_0.11.3      reshape2_1.4     scales_0.2.4     stringr_0.6.2   
[13] tools_3.1.2  

最佳答案

来自 github

library(DBI)
dbConnect(RSQLite::SQLite(), ...)

关于r - 使用 RSQLite 在 R 中加载 SQLite 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26824540/

相关文章:

以向量作为参数的 RSQLite 参数化查询

arrays - 生成一个新变量,对 R 中一组列的行进行平均

r - 图像作为图表中的标签?

r - units::set_units() 不会从变量中识别单位

python - 重新组织 sqlite 中的数据结构(使用 COUNT?)

android - SQLite.insert 返回 -1 但数据已插入数据库

php - PHP SQLite3Result::fetchArray重新执行查询

r - 使用 pivot_wider 从没有 values_from 列的逗号分隔向量创建唯一列

r - 如何使用RSQLite将数据表转换成SQLite表?