3
votes

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?

1
Did you have a look at the source code github.com/yihui/knitr/blob/master/R/engine.R and the description bookdown.org/yihui/rmarkdown/language-engines.html? I think you can manipulate the code to your own needs. - J_F
@J_F Your comment represents a valid answer. Please post an answer so I can sign off! Thanks - Andry
I just wrote a section on this topic in the R Markdown Cookbook: bookdown.org/yihui/rmarkdown-cookbook/custom-engine.html I hope it could be useful to you. Please feel free to let me know you have any comments or questions about this section. Thanks! - Yihui Xie

1 Answers

2
votes

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.