Xu Wang
Xu Wang

Reputation: 10597

knitr: keep cache when I make small change in chunk

I understandably broke cache when updating a chunk (however the result should be the same, it was cosmetic changes). However, I do not want to run the chunk again because it takes 1 week to run. How can I change the cache so that the new code thinks the cache holds?

I think I just need to change the file names in the cache folder. But I don't know what to change them to without running the code because knitr only writes the files after successful completion of the chunk.

Another motivation is that knitr cache can be invalidated when using different knitr versions. This happened to me between 1.5 and 1.5.33, the development versions. Also see here: R knitr: is it possible to use cached results across different machines?. I think if I find a solution to the above that can help with this.

Upvotes: 4

Views: 210

Answers (1)

Richie Cotton
Richie Cotton

Reputation: 121077

Using the knitr cache to store the results of a week-long simulation sounds a bit crazy susceptible to disaster.

My suggestion for a safer workflow is:

  1. Run the simulation and store the results in a file (csv, rda, whatever is suitable).

  2. Load that data inside a chunk (probably with echo = FALSE) near the start of your knitr report.

Now simulating and reporting are decoupled.

Upvotes: 5

Related Questions