Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

knitr

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: enter image description here

like image 755
user2554330 Avatar asked Oct 17 '22 23:10

user2554330


1 Answers

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.

like image 153
user2554330 Avatar answered Oct 27 '22 18:10

user2554330