Can `knitr` suppress execution or output in an sql chunk?

只谈情不闲聊 提交于 2019-12-12 16:02:23

问题


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;
```

I get this output:


回答1:


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.

I don't know if results="hide" is also supported, because I don't have mysql installed.



来源:https://stackoverflow.com/questions/40444521/can-knitr-suppress-execution-or-output-in-an-sql-chunk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!