Skip to content

Commit

Permalink
caching is an optional feature of knitr, so move digest to Suggests t…
Browse files Browse the repository at this point in the history
…o make the dependencies a little lighter
  • Loading branch information
yihui committed Jan 16, 2018
1 parent f54d061 commit 2ae9353
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -95,7 +95,6 @@ Depends:
R (>= 3.1.0)
Imports:
evaluate (>= 0.10),
digest,
highr,
markdown,
stringr (>= 0.6),
Expand All @@ -105,6 +104,7 @@ Imports:
Suggests:
formatR,
testit,
digest,
rgl (>= 0.95.1201),
codetools,
rmarkdown,
Expand Down
2 changes: 1 addition & 1 deletion R/block.R
Expand Up @@ -65,7 +65,7 @@ call_block = function(block) {
if (params$engine == 'R' && isFALSE(params$cache.comments)) {
content[['code']] = parse_only(content[['code']])
}
hash = paste(valid_path(params$cache.path, label), digest::digest(content), sep = '_')
hash = paste(valid_path(params$cache.path, label), digest(content), sep = '_')
params$hash = hash
if (cache$exists(hash, params$cache.lazy) &&
isFALSE(params$cache.rebuild) &&
Expand Down
2 changes: 1 addition & 1 deletion R/plot.R
Expand Up @@ -253,7 +253,7 @@ remove_plot = function(list, keep.high = TRUE) {
# replace the content of the recorded plot with MD5 digests so that merge_plot()
# will still work, and this will also save disk space for the case of cache=2
digest_plot = function(x, level = 1) {
if (!is.list(x) || level >= 3) return(digest::digest(x))
if (!is.list(x) || level >= 3) return(digest(x))
lapply(x, digest_plot, level = level + 1)
}

Expand Down
9 changes: 8 additions & 1 deletion R/utils.R
Expand Up @@ -891,7 +891,7 @@ extract_raw_output = function(text, markers = raw_markers) {
chunks = tokens = character(n)
for (i in seq_len(n)) {
chunks[i] = sub(r, '\\1', s[[1]][i])
tokens[i] = digest::digest(chunks[i])
tokens[i] = digest(chunks[i])
s[[1]][i] = gsub(r, paste0(markers[1], tokens[i], markers[2]), s[[1]][i])
}
regmatches(x, m) = s
Expand Down Expand Up @@ -1003,3 +1003,10 @@ optipng = function(dir = '.') {
files = list.files(dir, '[.]png$', recursive = TRUE, full.names = TRUE)
for (f in files) system2('optipng', shQuote(f))
}

digest = function(...) {
if (!loadable('digest')) warning2(
'You used a knitr feature that depends on the digest package. Make sure it is installed.'
)
digest::digest(...)
}

0 comments on commit 2ae9353

Please sign in to comment.