【问题标题】:RSQLite Error "hash is not an exported object"RSQLite 错误“哈希不是导出的对象”
【发布时间】:2022-01-23 05:19:25
【问题描述】:

我正在尝试抓取一些 pitchf/x 数据并将其存储在 SQLite 数据库中。但是,当我运行以下代码时收到以下错误:

library(RSQLite)
library(dplyr)
db <- src_sqlite("pitchfx.sqlite3", create = T)

这是错误:

    Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'drv' in selecting a method for function 'dbConnect': .onLoad failed in loadNamespace() for 'RSQLite', details:
  call: NULL
  error: 'hash' is not an exported object from 'namespace:rlang'
In addition: Warning message:
`src_sqlite()` is deprecated as of dplyr 1.0.0.
Please use `tbl()` directly with a database connection
This warning is displayed once every 8 hours.

我一直无法弄清楚如何解决这个问题。我已经重新安装了软件包,更新了 Rlang,重新启动了 R,但没有任何效果。我在 R 4.0.3 上。

【问题讨论】:

    标签: r sqlite


    【解决方案1】:

    规范方法(在该错误消息中暗示)是直接使用DBI 连接:

    library(DBI)   # dbConnect, dbWriteTable
    library(dplyr) # tbl
    mycon <- dbConnect(RSQLite::SQLite(), "pitchfx.sqlite3", create = TRUE)
    dbWriteTable(mycon, "mt", mtcars)
    tbl(mycon, "mt")
    # # Source:   table<mt> [?? x 11]
    # # Database: sqlite 3.33.0 [c:\Users\r2\Projects\ADS\pitchfx.sqlite3]
    #      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
    #    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    #  1  21       6  160    110  3.9   2.62  16.5     0     1     4     4
    #  2  21       6  160    110  3.9   2.88  17.0     0     1     4     4
    #  3  22.8     4  108     93  3.85  2.32  18.6     1     1     4     1
    #  4  21.4     6  258    110  3.08  3.22  19.4     1     0     3     1
    #  5  18.7     8  360    175  3.15  3.44  17.0     0     0     3     2
    #  6  18.1     6  225    105  2.76  3.46  20.2     1     0     3     1
    #  7  14.3     8  360    245  3.21  3.57  15.8     0     0     3     4
    #  8  24.4     4  147.    62  3.69  3.19  20       1     0     4     2
    #  9  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2
    # 10  19.2     6  168.   123  3.92  3.44  18.3     1     0     4     4
    # # ... with more rows
    

    并使用类似的东西

    tbl(mycon, "mt") %>%
      filter(cyl == 4L, disp > 120) %>%
      collect()
    # # A tibble: 5 x 11
    #     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
    #   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
    # 1  24.4     4  147.    62  3.69  3.19  20       1     0     4     2
    # 2  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2
    # 3  21.5     4  120.    97  3.7   2.46  20.0     1     0     3     1
    # 4  26       4  120.    91  4.43  2.14  16.7     0     1     5     2
    # 5  21.4     4  121    109  4.11  2.78  18.6     1     1     4     2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-13
      • 2021-03-31
      • 1970-01-01
      • 2012-01-23
      • 2019-07-22
      • 2015-03-19
      • 2016-06-19
      • 2014-04-21
      相关资源
      最近更新 更多