I am converting R Markdown to ConTeXt using R Markdown's render function and running into a bit of a problem. I'd like to be able to treat the R Markdown document as a ConTeXt document with R code embedded in it, similar to how knitr allows one to embed R code in a LaTeX file. I can ALMOST do this, except for the following issue: whenever an R code chunk is inside any sort of \startxxx ... \stopxxx environment, it doesn't get converted to ConTeXt properly in the rendering process.
Here's a minimal working example/reprex.
The following file temp1.Rmd compiles to ConTeXt correctly with rmarkdown::render("temp1.Rmd", rmarkdown::context_document(ext=".tex"), clean=FALSE)
:
```{r, echo=FALSE}
plot(rnorm(20))
```
The intermediate Markdown code that is produced is:
![](temp1_files/figure-context/unnamed-chunk-5-1.pdf)<!-- -->
The final ConTeXt code that is produced is:
{\externalfigure[temp1_files/figure-context/unnamed-chunk-5-1.pdf]}
This compiles correctly in ConTeXt.
However, the following file temp2.Rmd does not compile to ConTeXt correctly with rmarkdown::render("temp2.Rmd", rmarkdown::context_document(ext=".tex"), clean=FALSE)
:
\startalignment[center]
```{r, echo=FALSE}
plot(rnorm(20))
```
\stopalignment
The intermediate Markdown code that is produced is, as expected:
\startalignment[center]
![](temp2_files/figure-context/unnamed-chunk-6-1.pdf)<!-- -->
\stopalignment
But the final ConTeXt code that is produced is:
\startalignment[center]
![](temp2_files/figure-context/unnamed-chunk-6-1.pdf)<!-- -->
\stopalignment
This of course does not generate the desired graphic in ConTeXt.
As far as I can tell, this is a general issue: whenever an R code chunk occurs within a \startxxx ... \stopxxx environment (including \starttext ... \stoptext, which is obviously a problem), it gets to the intermediate Markdown file okay, but then it doesn't compile correctly to ConTeXt from there. The problem does not occur for inline R code, which compiles correctly wherever it is. That problem also does not occur if the \startxxx ... \stopxxx environment is included in a pandoc template (rather than in the R Markdown file itself), but that isn't sufficient for my purposes.
In short, what I'd like to do is be able to include R code chunks (not just inline R code) anywhere in an R Markdown file, including inside \startxxx ... \stopxxx enviornments. I'd appreciate any help that anyone can offer me on this.