0
votes

Can anybody help me understand how to turn off caching in LyX/knitr when I submit the following type of function calls to R via knitr:

\Sexpr{rnorm(1, 6, 1.1)}

or in a chunk:

<<echo=FALSE, cache=FALSE>>=
rnorm(1, 6, 1.1)
@

Each time I process the document I just get the exact same value as the first time. I know this must be simple, but it's driving me nuts. Thanks a lot, -Gary

1
Are you using set.seed anywhere in the document?Dason
Thanks for asking - no I'm not. This document is just a test, so there's really nothing else in it besides this simple command. -Gg5m
Do you have the same problem if you just compile everything without using Lyx? I can't reproduce that issue using RStudio.Dason
That's interesting. I can recreate this in RStudio by creating a new Sweave document processed via knitr, and of course the rnorm() function in the console returns a unique value each time as expected. If I change one of the args to the function, it gives a new number the first time, and the same number each subsequent time the document is created. So it's a knitr issue, not a LyX issue - that's useful information.g5m
I cannot reproduce it with LyX 2.0.4 + knitr 0.7.Yihui Xie

1 Answers

2
votes

Solved. There was a set.seed() call in my .Rprofile. When I remove it, this problem goes away in LyX. It threw me because in an R session, only the first call to rnorm() would be determined by the set.seed(), not subsequent calls to rnorm(), whereas from LyX a new session gets created each time a document is created. Since my example only had one call, I always got the same value. Thanks everybody - especially Yi Hui for making knitr.