RMarkdown: Print a code chunk "as is"
Code chunks
In order to print a code chunk as is, you need to use two tricks:
- break the chunk syntax by adding an empty string as inline R code to the chunk header.
- indent the code chunk with 4 spaces.
Using only the first trick mentioned:
{r eval=TRUE} n = 10 rnorm(x)
Now we also indent the code-chunk by 4 spaces because we want to show it in a preformatted block in the HTML output. The results is:
```{r eval=TRUE}
n = 10
rnorm(x)
```
Inline Code
Not executed inline code can be obtained by putting r knitr::inline_expr(‘1+1’) between ticks:
r 1+1
.