I used to think that the results = "asis"
chunk option is needed to include any chunk output verbatim in the rendered Rmarkdown document; otherwise the output would be formatted as console output (e.g. with leading ##
).
However, several functions such as knitr::kable()
seem to work just fine even without the results = "asis"
option whereas the table I created manually is formatted as console output in the example below.
How does knitr
know that the output is verbatim markdown and should be embedded as such?
My example:
---
title: Title
output: github_document
---
```{r}
# works without results = "asis"
knitr::kable(mtcars)
```
```{r}
# without results = "asis": formatted as console output
table <- "|col1|col2|\n|-|-|\n|a|b|"
writeLines(table)
```
```{r, results='asis'}
# works only with results = "asis"
writeLines(table)
```