You have to add a label to your code in minimal.R
corresponding to the chunk label in your LyX document, otherwise knitr
does not know where to insert the code.
## @knitr boring-random
set.seed(1121)
(x=rnorm(20))
mx <- mean(x)
vx <- var(x)
If you open the R script in the knitr
web page, you will see several lines of comments of the form ## @knitr label
. I will update the web page to clarify this. There is an alternative approach to specify the labels, which is documented in ?knitr::read_chunk
.
The second problem of your LyX document is you put read_chunk()
in the boring-random
chunk, but you really need to read the code before you insert it into a chunk.
<<setup>>=
read_chunk('minimal.R')
@
<<boring-random>>=
@