【发布时间】:2020-11-21 17:24:38
【问题描述】:
我试图按照下面的代码示例from here
library(dplyr)
con <- DBI::dbConnect(RSQLite::SQLite(), filename = ":memory:")
mtcars_db <- copy_to(con, mtcars)
mtcars_db %>%
filter(cyl > 2) %>%
select(mpg:hp) %>%
head(10) %>%
show_query()
DBI::dbDisconnect(con)
我得到了以下错误,而不是网站上的结果:
storage.mode(x) 中的错误
- mtcars_db %>% filter(cyl > 2) %>% select(mpg:hp) %>% head(10) %>% 。 show_query()
- withVisible(eval(quote(
_fseq(_lhs)), env, env))- eval(quote(
_fseq(_lhs)), env, env)- eval(quote(
_fseq(_lhs)), env, env)_fseq(_lhs)- freduce(值,
_function_list)- function_list[i]
- 过滤器(., cyl > 2)
DBI 对象似乎已正确加载,并打印:
# Source: table<mtcars> [?? x 11]
# Database: sqlite 3.30.1 []
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
即使只使用第一个管道也会发生错误:
mtcars_db %>%
filter(cyl > 2)
另外,is.data.frame(mtcars_db) 返回 FALSE。
有人知道这里出了什么问题吗?
这里的管道是否只适用于 R 数据帧?
(这是最新的 R 4.03 和 tidyverse,在 Ubuntu 20.04 下)
【问题讨论】:
-
请检查链接吗?在您链接到的页面上,我没有看到任何有问题的代码。
-
@Simon.S.A.当然,代码位于链接页面上的
17.6 Customising evaluation with functions。这是第二个代码块。