Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New chunk option: cache.rebuild #995

Merged
merged 4 commits into from
Apr 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion R/defaults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down