Is it possible to convert code chunks in an Rmd document to html without creating a whole web page?
I would like to use rmarkdown to format some content containing R code - but I would like the resulting html to be embedded in an existing html document.
For example, the following code:
### Example
```{r}
a <- 1 + 1
a
```
should result in the html snippet:
<h3>Example</h3>
<pre><code class="lang-r">
a <- 1 + 1
a
</code></pre>
At the moment, I can only do this using rmarkdown::render() which generates a complex self-contained file with embedded script elements that conflict with the existing website.
I am sure such a solution must exist, but I have not had any luck finding it!
Update: I realized that in your example you didn't evaluate the code chunk. To do this, you can specify the chunk option eval=FALSE. Then the output is closer to what you wanted: