I am writing about how to use R Markdown, and find that I am having to use R Markdown to write about R Markdown. I understand the notion of using regular markdown and enclosing R code chunks within standard markdown, but I don't understand the following example from the source code for " R Markdown: The Definitive Guide" (Chapter 2):
```{r include=FALSE}
b = '`r b[1]`' # an ugly hack; don't look at me
```
````markdown
This is a paragraph in an R Markdown document.
Below is a code chunk:
`r ''````{r}
fit = lm(dist ~ speed, data = cars)
b = coef(fit)
plot(cars)
abline(fit)
```
The slope of the regression is `r b[1]`.
````
Is there a reference for the syntax `r''````{r} line somewhere? Can someone explain what it does and why the "ugly hack" needed?
However, we have now simplified the syntax in recent knitr version. Doc is not up to date yet, but you could find how this works in the NEWS: knitr/NEWS.md at master · yihui/knitr · GitHub
It is the verbatim engine and embed engine.
For example
````{verbatim, lang = "markdown"}
We can output arbitrary content verbatim.
```{r}
1 + 1
```
The content can contain inline code like
`r pi * 5^2`, too.
````