如何在 R markdown 中指定不同的 cache.path (带文件名)?
How to specify different cache.path (w/ filename) in R markdown?
在 R markdown 中,如果我想将 cahce 保存在文件目录以外的其他目录中。为此,在夹头中,我将指定
{r chunkName, cache=TRUE, cache.path=cache.path = "../cache_filename/"}
但是如何避免输入文件名呢?有没有一种方法可以在没有 .Rmd 的情况下使用 title
名称或 filename
?
knitr
根据输入的文件名自动设置 cache.path
。如果你想做不同的事情,你可以这样做:
```{r}
origCache <- knitr::opts_chunk$get("cache.path")
base <- sub("_cache/.*$", "", origCache)
cat("The base of the filename is ", base)
knitr::opts_chunk$set(cache.path = paste0(base, "_new_cache"))
```
现在缓存将设置为文件名的基本部分,后跟“_new_cache”。
在 R markdown 中,如果我想将 cahce 保存在文件目录以外的其他目录中。为此,在夹头中,我将指定
{r chunkName, cache=TRUE, cache.path=cache.path = "../cache_filename/"}
但是如何避免输入文件名呢?有没有一种方法可以在没有 .Rmd 的情况下使用 title
名称或 filename
?
knitr
根据输入的文件名自动设置 cache.path
。如果你想做不同的事情,你可以这样做:
```{r}
origCache <- knitr::opts_chunk$get("cache.path")
base <- sub("_cache/.*$", "", origCache)
cat("The base of the filename is ", base)
knitr::opts_chunk$set(cache.path = paste0(base, "_new_cache"))
```
现在缓存将设置为文件名的基本部分,后跟“_new_cache”。