diff --git a/R/block.R b/R/block.R index 70b1641d56..2b5de79010 100644 --- a/R/block.R +++ b/R/block.R @@ -50,7 +50,7 @@ call_block = function(block) { } hash = paste(valid_path(params$cache.path, label), digest::digest(content), sep = '_') params$hash = hash - if (cache$exists(hash, params$cache.lazy)) { + if (cache$exists(hash, params$cache.lazy) && isFALSE(params$cache.rebuild)) { if (opts_knit$get('verbose')) message(' loading cache from ', hash) cache$load(hash, lazy = params$cache.lazy) if (!params$include) return('') @@ -78,7 +78,7 @@ cache1.opts = c('code', 'eval', 'cache', 'cache.path', 'message', 'warning', 'er # more options affecting cache level 2 cache2.opts = c('fig.keep', 'fig.path', 'fix.ext', 'dev', 'dpi', 'dev.args', 'fig.width', 'fig.height') # options that should not affect cache -cache0.opts = c('include', 'out.width.px', 'out.height.px') +cache0.opts = c('include', 'out.width.px', 'out.height.px', 'cache.rebuild') block_exec = function(options) { # when code is not R language @@ -145,7 +145,7 @@ block_exec = function(options) { # return code with class 'source' if not eval chunks res = if (is_blank(code)) list() else if (isFALSE(ev)) { list(structure(list(src = code), class = 'source')) - } else if (cache.exists) { + } else if (cache.exists && isFALSE(options$cache.rebuild)) { fix_evaluate(cache$output(options$hash, 'list'), options$cache == 1) } else in_dir( opts_knit$get('root.dir') %n% input_dir(), @@ -155,7 +155,7 @@ block_exec = function(options) { stop_on_error = if (options$error && options$include) 0L else 2L, output_handler = knit_handlers(options$render, options)) ) - if (options$cache %in% 1:2 && !cache.exists) { + if (options$cache %in% 1:2 && (!cache.exists || isTRUE(options$cache.rebuild))) { # make a copy for cache=1,2; when cache=2, we do not really need plots res.orig = if (options$cache == 2) remove_plot(res, keep == 'high') else res } diff --git a/R/defaults.R b/R/defaults.R index bfe9b76ada..61a93f01d7 100644 --- a/R/defaults.R +++ b/R/defaults.R @@ -56,7 +56,7 @@ opts_chunk = new_defaults(list( strip.white = TRUE, size = 'normalsize', background = '#F7F7F7', cache = FALSE, cache.path = 'cache/', cache.vars = NULL, cache.lazy = TRUE, - dependson = NULL, autodep = FALSE, + dependson = NULL, autodep = FALSE, cache.rebuild = FALSE, fig.keep = 'high', fig.show = 'asis', fig.align = 'default', fig.path = 'figure/', dev = NULL, dev.args = NULL, dpi = 72, fig.ext = NULL, fig.width = 7, fig.height = 7,