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.

1 Answer 1


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .