Search code examples
rstudior-markdownbookdown

How to create custom blocks in RMarkdown?


In RMarkdown, I know I can type something like this:

```{r}
sum <- 1 + 1
```

To create a block to be evaluated inside the R session for the currently processed .Rmd document. I know there are others where the label inside {<label>} changes and triggers a different behavior. Fx, [Bookdown]{https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#equations} defines: {theorem} and others.

What I need

I wanna be able to create my own block and execute certain code to handle its content:

```{myblock}
This text will appear styled different (for example)
```

I do not need to create a new block for styling text, the one above is just an example. How can I achieve this customization?


Solution

  • You can find information of supported engines in the official documentation of the knitr package.

    Also have a look at the code.

    Now you can manipulate the code to your own needs, build the package and use it with your own needs.