5

Issue solved, see answers for details.

I would like to run some code (with knitr) on a more powerful server and then maybe have the possibility of making small changes on my own laptop. Even copying across the entire folder, it seems that the cache is rebuilt when re-compiling locally, is there a way to avoid that and actually use the results in the cache?

2 Answers2

5

Update: the problem arose from different versions of knitr on different machines.


In theory, yes -- if you do not change anything, the cache will be kept. In practice, you have to check carefully what the "small changes" are. The documentation page for cache has explained when the cache will be rebuilt, and you need to check if all three conditions are met.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Many thanks for your answer. I copied across the folders without changing anything before re-compiling on a different machine, so I guess the 3 conditions are met. I noticed now that the two machines run different versions of R (namely 2.15.1 first and 3.0 later locally). However I am not using the cache.extra option, could it still be that the difference in the versions is prompting the cache to be rebuilt? On the other hand I was also wondering whether the datetime issues mentioned by @Greg might have an effect. – user2252705 Jun 13 '13 at 07:37
  • The date/time does not matter. Neither does the R version matter. You just need to make sure the `knitr` versions are the same on the two machines, so check `library(knitr); sessionInfo()` – Yihui Xie Jun 13 '13 at 19:02
  • I just checked and discovered that the versions of `knitr` are actually different. Thanks for the suggestion, I will try to redo the experiment with the same version on both machines and hope that this will fix the problem. – user2252705 Jun 13 '13 at 19:43
  • @user2252705 glad you figured it out; normally this should not be a problem -- I have been trying not to break cache across different versions of knitr, but sometimes I have to – Yihui Xie Jun 13 '13 at 20:59
  • the experiment was successful, when compiling with the same version of `knitr` on both machines the cache feature works as I expected. Many many thanks again for your help. – user2252705 Jun 14 '13 at 20:07
0

I wonder if in addition to @Yihui's answer if the process of copying from one machine to another changes the datetimes on the files so that they look out of date even when nothing has changed.

Look at the dates on the files involved after copying. If you can figure out which files need to be newer than others then touching them may prevent the rebuilding.

Another option would be to just paste in the chached pieces directly so that they are not rerun (though that means you have to rerun and repaste manually if you change anything in those parts).

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • Many thanks for your answer. There are a number files in the cache, so that `touch`ing them in the right order does not seem very practical. I guess the same applies to the manual paste, though I am not quite sure I understand what you meant. Thanks again. – user2252705 Jun 13 '13 at 07:46
  • @user2252705, by paste it in I mean just take the output from the part you want cached and paste it directly into the file rather than having the commands that will generate the output. – Greg Snow Jun 13 '13 at 15:31