is it possible to compile R latex via knitr in a modula way

114 views Asked by At

Is there any way to compile knitr subfiles separately? What I have in mind is something like the package subfiles for latex just in combination with R/knitr/Sweave? This would be great in case one has two exercises a first exercise with heavy computations and don't want to compile the entire exercise always while working and testing the second one.

2

There are 2 answers

0
user2554330 On

The patchDVI package does this for Sweave. I imagine it would be possible (maybe even easy) to modify it to do the same for knitr.

For example, in Sweave, you define variables in a chunk like so:

<<>>=
.TexRoot <- "main.tex"
.SweaveFiles <- c("subfile1.Rnw", "subfile2.Rnw")
@

and after Sweave is finished running that file, patchDVI will check whether the files subfile1.Rnw and subfile2.Rnw also need to be run, then will run LaTeX on the main.tex file once everything is up to date.

0
Gregor Thomas On

You don't need to do anything difficult, just use the cache options. Lots of details here, but it's probably as simple as specifying cache = T in the chunk options of your first exercise.