Skip to content

Commit

Permalink
Merge pull request #866 from haozhu233/issue865
Browse files Browse the repository at this point in the history
Clean up in case of error.
  • Loading branch information
dmurdoch authored Oct 30, 2024
2 parents cc2bd72 + b0f6bb4 commit 06d2dbe
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/save_kable.R
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ save_kable_latex <- function(x, file, latex_header_includes, keep_tex, density)
file_no_ext <- tools::file_path_sans_ext(temp_tex_file)

owd <- setwd(dirname(temp_tex_file))
on.exit(setwd(owd), add = TRUE)

if (!keep_tex) {
temp_file_delete <- paste0(file_no_ext, c(".tex", ".aux", ".log"))
on.exit(unlink(temp_file_delete), add = TRUE)
}

if (!requireNamespace("tinytex", quietly = TRUE)) {
system(paste0("xelatex -interaction=batchmode ",
Expand All @@ -260,10 +266,6 @@ save_kable_latex <- function(x, file, latex_header_includes, keep_tex, density)
tinytex::xelatex(gsub(pattern = " ", replacement = "\\ ",
temp_tex_file, fixed = TRUE))
}
if (!keep_tex) {
temp_file_delete <- paste0(file_no_ext, c(".tex", ".aux", ".log"))
unlink(temp_file_delete)
}

table_img_info <- NULL
if (tools::file_ext(file) != "pdf") {
Expand All @@ -285,8 +287,6 @@ save_kable_latex <- function(x, file, latex_header_includes, keep_tex, density)
density = density)
}

setwd(owd)

out <- paste0(file_no_ext, ".", tools::file_ext(file))
attr(out, "info") <- table_img_info
return(invisible(out))
Expand Down

0 comments on commit 06d2dbe

Please sign in to comment.