I have a LyX document (report class) called mwe.lyx and I would like to execute the following Rmd chunk called "mwe.Rmd".

{r, eval = FALSE, echo = TRUE, cache = FALSE} 2+2

Of course, I can simply use the chunk environment in LyX, but I would strongly prefer a solution in which I can keep my Rmd files external to my LyX file without copy-pasting from Rmd to LyX.

Alternately, if I could have the functionality of child document in LyX with the graphical display given by knitr, that would also be excellent.


Yihui Xie, author of knitr, writes in his new book "Dynamic Documents with R and knitr" that:

Note that currently Rnw is the only possible format to use in LYX. It seems we are mixing R code with LYX, but LYX is really only a wrapper so we are actually embedding R code in Rnw documents.

Unfortunately, it seems that I will have to either reformat all my materials from .Rmd's to .Rnw's, reformat them to regular R files and bring them using read_chunk or source, or copy-paste all of my R code into LyX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.