如果他们有Rscript
个SQLite调用,我无法使用dplyr
呈现Rmarkdown文档。拿这个MWE(test.Rmd
)来调用dplyr::lahman_sqlite()
表的本地副本中的表。
---
title: "TestFile"
output: html_document
---
```{r setup, include=FALSE}
library(dplyr)
lahman <- src_sqlite("lahman.sqlite")
```
```{r}
tbl(lahman, "Batting")
```
在实时R控制台会话中,我可以调用rmarkdown::render("test.Rmd")
,此文档按预期构建。但是如果我在命令行上调用Rscript -e 'rmarkdown::render("test.Rmd")'
,我会收到以下错误:
Quitting from lines 12-13 (test.Rmd)
Error in UseMethod("db_query_fields") :
no applicable method for 'db_query_fields' applied to an object of class "SQLiteConnection"
Calls: render ... make_tbl -> structure -> op_base_remote -> db_query_fields
我在下面附加了sessionInfo,但是我在OS X和Ubuntu上都重复了这个错误。
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin15.5.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_0.5.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.5 digest_0.6.9 assertthat_0.1 R6_2.1.2 DBI_0.4-1 formatR_1.4 magrittr_1.5 evaluate_0.9
[9] RSQLite_1.0.0 stringi_1.1.1 rmarkdown_0.9.6 tools_3.3.1 stringr_1.0.0 Lahman_4.0-1 yaml_2.1.13 htmltools_0.3.5
[17] knitr_1.13 tibble_1.0
答案 0 :(得分:3)
问题来自于使用Rscript
时未加载methods
包。因此,需要通过在设置块中添加library(methods)
来显式加载它。