Skip to content

Commit

Permalink
fix #1717: signal an error if any files do not exist when included vi…
Browse files Browse the repository at this point in the history
…a include_graphics()
  • Loading branch information
yihui committed Jan 16, 2020
1 parent 03efcd7 commit 1648923
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.27
Version: 1.27.1
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Adam", "Vogt", role = "ctb"),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# CHANGES IN knitr VERSION 1.28

## MINOR CHANGES

- `include_graphics(files)` will signal an error if any `files` do not exist and are not web resources (thanks, @hadley, #1717).

# CHANGES IN knitr VERSION 1.27

## NEW FEATURES
Expand Down
3 changes: 3 additions & 0 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ include_graphics = function(
path[i] = path2[i]
}
path = native_encode(path)
if (length(p <- path[!is_web_path(path) & !file.exists(path)])) stop(
'Cannot find the file(s): ', paste0('"', p, '"', collapse = '; ')
)
structure(path, class = c('knit_image_paths', 'knit_asis'), dpi = dpi)
}

Expand Down
5 changes: 5 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ is_abs_path = function(x) {
if (is_windows()) grepl('^(\\\\|[A-Za-z]:)', x) else grepl('^[/~]', x)
}

# paths of web resources?
is_web_path = function(x) {
grepl('^(f|ht)tps?://', x)
}

# is tikz device without externalization?
is_tikz_dev = function(options) {
'tikz' %in% options$dev && !options$external
Expand Down

0 comments on commit 1648923

Please sign in to comment.