How to show markdown in R Markdown

I want to show R Markdown in slides for my students. Is there a way to mark material to be displayed as it appears in the RMD file, rather than as instructions as to how to knit?

For example, I might want

# A Header

to appear just like that, including the hash tag and in blue rather than generating a new header.

Probably obvious, but not to me...

You can use md

````md
# A Header
````

Very helpful. Thanks.

Can I ask whether the inclusion of "md" is part of the code or just a useful comment?

It's what causes it to be interpreted as Markdown, like you see with R chunks

```{r}
# your code here
```

Got it. Thanks once more.

One more piece...

I also want to be able to include the R code blocks including the surrounding {r}... and backquotes. For example,

 ```{r setup, include=FALSE}
> knitr::opts_chunk$set(echo = TRUE, comment = NULL, options(width = 58))

The answer to my question appears to be to use a "verbatim code chunk." While a little kludgey, this is explained in The R Markdown Cookbook at https://bookdown.org/yihui/rmarkdown-cookbook/verbatim-code-chunks.html.

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

Done. Clearly good etiquette. Thanks for pointing this out to me.

1 Like

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.