From b0f6bb4393a3285b4a643e4dc4c27307c188ce66 Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Wed, 30 Oct 2024 06:16:43 -0400 Subject: [PATCH] Clean up in case of error. --- R/save_kable.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/save_kable.R b/R/save_kable.R index 1aa05ee..8040d9c 100644 --- a/R/save_kable.R +++ b/R/save_kable.R @@ -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 ", @@ -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") { @@ -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))