Caching external knitr code from multiple Rmd files

I find it difficult to get knitr to use caching between two Rmd documents sharing common source code in an external R file. Although I can see on the file system that both documents write the output to the same set of cache files, every time one Rmd document is bound to HTML, it overwrites the cache files created by knitting the previous Rmd. Several jerseys of the same Rmd file successfully use the cache without re-executing common code. Did I miss something in setting cache options to support multiple documents?

The following are sample code and sessionInfo (). Thanks in advance for any help you can offer.

test1.R

## @knitr source_chunk_1
x <- Sys.time()
x

test1a.Rmd

```{r set_global_options, cache=FALSE}
library(knitr)
opts_knit$set(self.contained = FALSE)
opts_chunk$set(cache = TRUE, cache.path = "knitrcache/test-")
read_chunk("test1.R")
```

```{r local_chunk_1, ref.label="source_chunk_1"}
```

test1b.Rmd

```{r set_global_options, cache=FALSE}
library(knitr)
opts_knit$set(self.contained = FALSE)
opts_chunk$set(cache = TRUE, cache.path = "knitrcache/test-")
read_chunk("test1.R")
```

```{r local_chunk_1, ref.label="source_chunk_1"}
```

sessionInfo

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252           
LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
other attached packages:
[1] knitr_1.5
loaded via a namespace (and not attached):
[1] evaluate_0.5.3   formatR_0.10     rmarkdown_0.2.05 stringr_0.6.2    tools_3.1.0     
+4
1

knitr github , . .R , digest() :

hash = paste(valid_path(params$cache.path, label), digest::digest(content), sep = '_')

, , Rmd . fig.path , .

 > content$fig.path
[1] "./test1a_files/figure-html/"  

> content$fig.path
[1] "./test1b_files/figure-html/"

fig.path Rmd , . , Rmd, .

Test1.R

## @knitr source_chunk_1
x <- Sys.time()
x

test1a.Rmd

```{r set_global_options, cache=FALSE}
library(knitr)
opts_knit$set(self.contained = FALSE)
opts_chunk$set(cache = TRUE, cache.path = "knitrcache/test-", fig.path = "knitrfig/test-")
read_chunk("test1.R")
```

```{r local_chunk_1, ref.label="source_chunk_1"}
``` 

test1b.Rmd

```{r set_global_options, cache=FALSE}
library(knitr)
opts_knit$set(self.contained = FALSE)
opts_chunk$set(cache = TRUE, cache.path = "knitrcache/test-", fig.path = "knitrfig/test-")
read_chunk("test1.R")
```

```{r local_chunk_1, ref.label="source_chunk_1"}
``` 
+1

Source: https://habr.com/ru/post/1542977/


All Articles