`knitr`可以抑制执行或在SQL块中输出吗? [英] Can `knitr` suppress execution or output in an sql chunk?
本文介绍了`knitr`可以抑制执行或在SQL块中输出吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的文档运行sql并显示结果.我不希望通过不运行块或隐藏输出来显示任何输出.
The document below runs the sql and shows the results. I don't want any output to show up, either by not running the chunk, or by hiding the output.
有没有办法做到这一点?
Is there a way to do this?
---
output: html_document
---
## Hide SQL Output
First, set up a temporary database:
```{r}
library(RSQLite)
conn <- dbConnect(SQLite(), tempfile())
df <- data.frame(value = runif(1))
dbWriteTable(conn, "TestTable", df)
```
Now show a query, but try not to run it, and try
to hide the output. Neither works: it runs, and
displays the table.
```{sql connection = conn,results="hide",eval=FALSE}
SELECT * FROM TestTable;
```
我得到以下输出:
推荐答案
我找到了一种解决方法.如果我使用mysql
引擎而不是sql
引擎,那么至少eval = FALSE
可以工作:
I found a workaround. If I use the mysql
engine instead of the sql
engine, then at least eval = FALSE
works:
```{mysql eval=FALSE}
SELECT * FROM TestTable;
```
将以突出显示语法的方式显示代码,但不执行任何操作.
will display the code with syntax highlighting but not execute anything.
我不知道是否还支持results="hide"
,因为我没有安装mysql.
I don't know if results="hide"
is also supported, because I don't have mysql installed.
这篇关于`knitr`可以抑制执行或在SQL块中输出吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文