r - Where is knitr cached output stored? -


in cache directory, 1 can use lazyload view environment @ end of chunk. output of chunk (that printed if document compiled) stored?

use source!

look @ source code here https://github.com/yihui/knitr/blob/master/r/cache.r

you can see mechanism explained here (within new_cache function)

# when cache=3, code output stored in .[hash], cache=true won't lose # output cachesweave does; cache=1,2, output evaluate() list cache_output = function(hash, mode = 'character') {   get(sprintf('.%s', hash), envir = knit_global(), mode = mode, inherits = false) } 

i.e. stored object in knit_global environemnt`

you can inspect these objects ls(knitr::knit_global(), = true)

i.e. 3 simple chunks below

```{r, cache=true} summary(cars) ```  ```{r }  ls(knitr::knit_global(), = true)  ```   ```{r }  get(ls(knitr::knit_global(), = true)[1], knitr::knit_global())  ``` 

give following output

summary(cars) ##      speed           dist     ##  min.   : 4.0   min.   :  2   ##  1st qu.:12.0   1st qu.: 26   ##  median :15.0   median : 36   ##  mean   :15.4   mean   : 43   ##  3rd qu.:19.0   3rd qu.: 56   ##  max.   :25.0   max.   :120  ls(knitr::knit_global(), = true) ## [1] ".preview-2b40490e2591_cache/unnamed-chunk-1_766fcb86fd875984b372e3c23210bfad" ## [2] "metadata"  get(ls(knitr::knit_global(), = true)[1], knitr::knit_global()) ## [1] "\n```r\nsummary(cars)\n```\n\n```\n##      speed           dist    \n##  min.   : 4.0   min.   :  2  \n##  1st qu.:12.0   1st qu.: 26  \n##  median :15.0   median : 36  \n##  mean   :15.4   mean   : 43  \n##  3rd qu.:19.0   3rd qu.: 56  \n##  max.   :25.0   max.   :120\n```" 

if have exited r, can load data file *.rdata in cache folder using load command. also, output result of get, consider use cat turn "\n" lines , should original output.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -