Skip to content

Commit 9f233f5

Browse files
committed
fix #2025: the -o argument of asymptote takes the basename of the output file path instead of the actual path now, so if we pass foo.png to -o, we will get foo.png.png
to fix this problem, we check if foo.png exists; if not, check foo.png.png
1 parent ea278f6 commit 9f233f5

File tree

6 files changed

+15
-5
lines changed

6 files changed

+15
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: knitr
22
Type: Package
33
Title: A General-Purpose Package for Dynamic Report Generation in R
4-
Version: 1.51.1
4+
Version: 1.51.2
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
77
person("Abhraneel", "Sarma", role = "ctb"),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ import(grDevices)
152152
import(graphics)
153153
import(stats)
154154
import(utils)
155+
importFrom(xfun,file_exists)
155156
importFrom(xfun,file_ext)
156157
importFrom(xfun,file_string)
157158
importFrom(xfun,html_escape)

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGES IN knitr VERSION 1.52
22

3+
## BUG FIXES
4+
5+
- Due to a change in Asymptote, the output file may not be recognized or included correctly (thanks, @DeliciousRoastPotato @shangeconnew, #2025).
36

47
# CHANGES IN knitr VERSION 1.51
58

@@ -9,7 +12,7 @@
912
- `knit()` produces 'knitr processing' and 'knitr output' spans when starting and finishing an operation
1013
- `knit()` produces 'knit' spans for each chunk, recording attributes such as the label and knit engine
1114

12-
- Added support for hooks that get executed before and after knitting. To register a hook before knitting starts, use `knitr::knit_hooks$set(before.knit = function() {})`. Similarly, the hook `after.knit` can be registered and will be executed after knitting is finished.
15+
- Added support for hooks that get executed before and after knitting (thanks, @cderv #2223, @arnaudgallou #2419). To register a hook before knitting starts, use `knitr::knit_hooks$set(before.knit = function() {})`. Similarly, the hook `after.knit` can be registered and will be executed after knitting is finished.
1316

1417
## BUG FIXES
1518

R/engine.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,13 @@ eng_plot = function(options) {
403403
output = function(options, code, output, file) {
404404
extra = if (options$eval) {
405405
# move the generated plot (with a temp filename) to fig.path
406-
f1 = with_ext(file, ext)
406+
if (cmd == 'asy' && !file_exists(f1 <- with_ext(file, ext))) {
407+
# asymptote may geneate file.ext.ext (see #2025)
408+
f1 = paste0(f1, '.', ext)
409+
}
410+
if (!file_exists(f1)) stop(
411+
'The command did not generate the expected plot file: ', f1
412+
)
407413
f2 = paste(fig_path(), ext, sep = '.')
408414
xfun::dir_create(dirname(f2))
409415
unlink(f2)

R/package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#' FAQ's: \url{https://yihui.org/knitr/faq/}
2727
#' @importFrom xfun file_ext html_escape is_windows loadable parse_only
2828
#' sans_ext try_silent with_ext read_utf8 write_utf8 file_string
29-
#' is_R_CMD_check is_abs_path
29+
#' is_R_CMD_check is_abs_path file_exists
3030
'_PACKAGE'
3131

3232
.knitEnv = new.env()

R/utils-conversion.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ rnw2pdf = function(
115115
# On Windows, when tweaking the content, users may forget to close the PDF
116116
# file (thus can't be written). Since knitting may take quite some time, it's
117117
# better to check the write permission of the output file in advance.
118-
if (xfun::file_exists(output) && !file.remove(output)) stop(
118+
if (file_exists(output) && !file.remove(output)) stop(
119119
"The file '", output, "' cannot be removed (may be locked by a PDF reader)."
120120
)
121121
old = opts_chunk$set(error = error)

0 commit comments

Comments
 (0)