Blogdown writing content tricks

This blogpost is primarily written for my future self. I am notoriously forgettting how things are done. This is partly linked to me playing around with too many things at the same time or simply not having used a specific feature for a while. This page hopefully helps filling in as an aide memoire.

Displaying Code Chunks Without Executing Them

Code Chunk Blocks

Yihui provides examples for displaying verbatim code chunks. The trick is to destroy the header of the code chunk by inserting an what they call an empty string as inline r code. I rather say, insert two tick marks as inline code after the chunk header as shown here `r ''`. These will create the empty string.

{r eval=TRUE} n = 10 rnorm(x)

code chunk header with inline r code for two ticks

code chunk header with inline r code for two ticks

In order to have the code chunks displayed as a block, intend the whole block by inserting 4 spaces.

```{r eval = TRUE}
n = 10
rnorm(x)
```

Inline R Code

If you want to display inline r code, c.f. above, Yihui’s FAQ #7 offers 2 ways of doing this:

  1. Single backticks can be escaped by double backticks. In order to trick R into not evaluating the inline code, insert a line break immediately after the first backtick and the folloing r `r. Note: if you check the Rmd of this post, you can see this is how I displayed the two tick marks as inline code above :). As an example, this might help `r 1 + 1 `. The inline r code is shown verbatim without executing it.
  2. Alternatively, knitr() offers an inline expression function, i.e. knitr::inline_expr(). With this you can write `r 1 + 1`.
Avatar
Rainer Koelle
Head Operational ANS Performance

I am a pilot, air traffic controller, and engineer, and work for EUROCONTROL, Performance Review Unit. My research interests revolve around operational air navigation and/or air transportation system performance applying a mix of data science and system analytics. In a side role I am also interested in time-critical decision making applied in aviation security and critical infrastructure protection.

Related

Next
Previous