I believe that cache.rebuild does not replace the old cache for chunks with cache=2.
Here's an example. Run these two chunks once:
<<testChunk1, echo=TRUE, eval=TRUE, cache=FALSE>>=
x <- 2
@
<<testChunk2, echo=TRUE, eval=TRUE, cache=2>>=
print(date())
x+3
@
Now, modify the value of 'x' in first chunk and require that cache for second chunk be rebuilt:
<<testChunk1, echo=TRUE, eval=TRUE, cache=FALSE>>=
x <- 20
@
<<testChunk2, echo=TRUE, eval=TRUE, cache=2, cache.rebuild=TRUE>>=
print(date())
x+3
@
The correct value of 23 is now displayed in the output document in the second chunk (along with current date). BUT! if you now re-run the file again and remove the cache.rebuild:
<<testChunk1, echo=TRUE, eval=TRUE, cache=FALSE>>=
x <- 20
@
<<testChunk2, echo=TRUE, eval=TRUE, cache=2>>=
print(date())
x+3
@
then the old value of 5 (and the old date!) will show up in the output document in the second chunk. This does NOT happen if cache=3.
I think the reason are these lines in the block_exec() function (lines 258-261 in block.R)
if (options$cache < 3) {
if (!cache.exists) block_cache(options, res.orig, objs)
} else block_cache(options, output, objs)
}
It looks like for cache=2, the cache is written out if it does not exist, but is NOT re-written if a) it exists, b) no changes are made to code/options, c) cache.rebuild=TRUE.
I would have expected cache.rebuild=TRUE to trigger cache re-writing here and am wondering if this is a design feature (i.e., something else breaks if cache is actually re-written for cache=2 use cases).
I came across this when switching my default cache value to cache=2 in order to use hook_purl functionality.
Thanks!
Oleg.