I am trying to use read_chunk()
to separate my R code from my Lyx file as explained here.
My Lyx setup compiled the knitr_minimal.pdf
from knitr_minimal.lyx
without any issues.
But then I tried to replace this:
<<boring-random>>=
set.seed(1121)
(x=rnorm(20))
mx <- mean(x)
vx <- var(x)
@
The first element of x is \Sexpr{x[1]}. Its mean is \Sexpr{mx}.
with this:
<<boring-random, cache=FALSE>>=
read_chunk('minimal.R')
@
The first element of x is \Sexpr{x[1]}. Its mean is \Sexpr{mx}.
The script minimal.R
is saved in the same directory, and consists of just
set.seed(1121)
(x=rnorm(20))
mx <- mean(x)
vx <- var(x)
I saved the modified file as knitr_minimal1.lyx
and compiled it. The file knitr_minimal1.pdf
compiled alright, but instead of
The first element of x is 0.145. Its mean is 0.3217.
I see
The first element of x is Error in eval(expr, envir, enclos) : object âxâ not found. Its mean is Error in eval(expr, envir, enclos) : object âmxâ not found.
I'd be grateful for any advice.