Invalidate a chunk's cache when uncached chunk changes

后端 未结 1 725
傲寒
傲寒 2021-01-12 19:38

I have a question regarding the knitr chunk option \"dependson\". As far as I understood the manual this option should be used to specify which other cached chunks a cached

相关标签:
1条回答
  • 2021-01-12 20:01

    Yes, you can make var a part of the chunk options, e.g.

    <<cached, cache=TRUE, cache.whatever=var>>=
    @
    

    cache.whatever is not an official chunk option name, but you can use arbitrary options in knitr, and they will affect the cache invalidation. In this case, when var is updated, the cache will be updated.

    If you want var to affect all cached chunks, you can set it as a global option, but remember to set it as an unevaluated expression:

    opts_chunk$set(cache.whatever = quote(var))
    

    You can use arbitrary R expressions inside quote(), so if you have more variables, you can put them in a list, e.g.

    opts_chunk$set(cache.whatever = quote(list(var1, var2)))
    
    0 讨论(0)
提交回复
热议问题