Writing about R markdown in using Bookdown

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?

1 Like

Documentation about this syntax is there: 5.6 Verbatim code chunks | R Markdown Cookbook

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.
````
1 Like

This is terrific! Thanks for both the reference to the older syntax and for the update! The new version looks very clean. Thanks again.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.