3

Lyx file F

knitr chunk caches a value for x
then text A contains several Sexpr{} calls, including Sexpr{x}

Compiling F to pdf works fine

Now I move text A into a separate LyX file C, make C a child file with F the master file

Rewrite F -- should produce "text A" twice

knitr chunk caches a value for x
text A 
\include(C)

Every thing works fine, compilation produces "text A" twice, EXCEPT \Sexpr{x} in the included portion cannot find the cached value. I've reviewed knitr and knitr/LyX documentation and numerous help sites, but cannot figure out how caching works (or fails to work) in this situation.

Brian Diggs
  • 57,757
  • 13
  • 166
  • 188

1 Answers1

3

That is not a problem of cache, but a problem of LyX, or a feature that has not been implemented. At the moment, the LyX child documents are treated as independent files, meaning that they are compiled in separate R sessions, so variables cannot be shared across documents. You may file a feature request to LyX developers. The key point is, when a LyX contains the knitr or Sweave module and is included as a child document of another document, it should not be compiled separately (hand this job over to knitr or Sweave).

Anyway, personally I do not find this a big problem -- I always put everything in one LyX document.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Thanks. Very clear, and along the lines of what I expected. There are a number of obvious workarounds, but it would be nice in a large knitr-lyx document with many R graphics to limit test compilations to one section. Thanks for the prompt response. – user2174495 Mar 17 '13 at 15:01