I am trying to use read_chunk() to separate my R code from my Lyx file, as described here .
My Lyx setup compiled knitr_minimal.pdf from knitr_minimal.lyx without any problems.
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 value is \ Sexpr {mx}.
with this:
<<boring-random, cache=FALSE>>= read_chunk('minimal.R') @
The first element of x is \ Sexpr {x [1]}. Its value is \ Sexpr {mx}.
script minimal.R stored in the same directory and consists only of
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 in order, but instead
The first element of x is 0.145. Its value is 0.3217.
I see
The first element of x is an error in eval (expr, envir, enc): object x was not found. Its value is an error in eval (expr, envir, enc): the mx object was not found.
I would be grateful for any advice.
source share