【问题标题】:r language - sqldf package not seeing any of my datafilesr 语言 - sqldf 包没有看到我的任何数据文件
【发布时间】:2017-11-27 16:02:42
【问题描述】:

我已经在我的系统上重新安装了包 sqldf,但是每当我运行任何 sql 查询时,我都会得到

Error in rsqlite_send_query(conn@ptr, statement) : 
  no such table

无论名称或表格如何

我查看了有关设置软件包等的所有指南并阅读了 pdf,但由于某种未知原因,它无法在我的机器上正常工作。

示例代码 - “复制堆栈溢出的更正答案,因此应该可以正常工作”

library(sqldf)

apps.rsd <- structure(list(appid = c(173L, 717L, 996L, 209L, 602L, 255L), 
                           cid = c(4L, 15L, 21L, 5L, 13L, 6L), 
                           price = c(0, 0, 0, 1.99, 0, 0.76), 
                           count = c(411, 411, 210, 18, 921, 22), 
                           sum = c(1226, 1870, 871, 66, 3948, 86), 
                           mean = c(2.98296836982968, 4.54987834549878, 4.14761904761905, 3.66666666666667, 4.28664495114007, 3.90909090909091), 
                           sd = c(1.73897694746568, 0.958668345866094, 1.31370760232218, 1.33373734360862, 1.62114131819336), 
                           rcount = c(3, 3, 3, 5, 5, 7), 
                           rsum = c(7, 0, 0, 13, 0, 19), 
                           rsd = c(2.3094010767585, 2.3094010767585, 2.3094010767585, 2.19089023002066, 2.19089023002066, 2.1380899352994)), 
                      .Names = c("appid", "cid", "price", "count", "sum", "mean", "sd", "rcount", "rsum", "rsd"), 
                      class = c("data.table", "data.frame"), 
                      row.names = c(NA, -6L))  

sqldf("SELECT appid FROM 'apps.rsd' WHERE rcount > 50")**

【问题讨论】:

  • RSQLite 2.0 不向后兼容并破坏 sqldf。使用旧版本的 RSQLite 或使用 github 上的 sqldf 开发版本。 devtools::install_github("ggrothendieck/sqldf")
  • 非常感谢,这让我头疼
  • 与 RSQLite 2.0 一起使用的新 sqldf 0.4-11 现在在 CRAN 上。

标签: r sqldf


【解决方案1】:

将表的名称放在引号 ' ' 中使其工作,因为表的名称中有一个句号,这会导致 SQL 出现问题

> sqldf("SELECT appid FROM 'apps.rsd' WHERE rcount > 50")
Loading required package: tcltk
[1] appid
<0 rows> (or 0-length row.names)
Warning message:
Quoted identifiers should have class SQL, use DBI::SQL() if the caller performs the quoting.


> sqldf("SELECT appid FROM apps.rsd WHERE rcount > 50")
Error in rsqlite_send_query(conn@ptr, statement) : 
  no such table: apps.rsd


> sqldf("SELECT appid FROM 'apps.rsd' WHERE rcount > 0")
  appid
1   173
2   717
3   996
4   209
5   602
6   255

【讨论】:

  • 在我的示例中它已经在引号中。我正在使用一个与我的问题相近的示例,该示例已按照您刚才描述的方式解决。我机器上的包似乎有问题,它只是没有指向内存
  • 我也试过把它指向内存,还是看不到表格。
  • 测试
  • 为了更好地解释 - 我删除了“。”将其替换为 _ ie apps_rsd - 同样的问题
  • 检查上面。你也可以重新安装 sqldf
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-15
相关资源
最近更新 更多