finishing save_kable latex part
diff --git a/R/save_kable.R b/R/save_kable.R
index 85ed54a..7870af7 100644
--- a/R/save_kable.R
+++ b/R/save_kable.R
@@ -24,7 +24,7 @@
bs_theme = "simplex", self_contained = TRUE,
extra_dependencies = NULL, ...,
latex_header_includes = NULL, keep_tex = FALSE) {
- if (attr(x, "format") == "latex") {
+ if (!is.null(attr(x, "format")) && attr(x, "format") == "latex") {
return(save_kable_latex(x, file, latex_header_includes, keep_tex))
}
return(save_kable_html(x, file, bs_theme, self_contained,
@@ -36,6 +36,7 @@
dependencies <- list(
rmarkdown::html_dependency_jquery(),
rmarkdown::html_dependency_bootstrap(theme = bs_theme),
+ rmarkdown::html_dependency_font_awesome(),
html_dependency_kePrint()
)
if (!is.null(extra_dependencies)) {
@@ -66,6 +67,8 @@
unlink("lib", recursive = TRUE)
}
}
+
+ return(file)
}
save_kable_latex <- function(x, file, latex_header_includes, keep_tex) {
@@ -89,7 +92,7 @@
)
temp_tex <- paste(temp_tex, collapse = "\n")
- temp_tex_file <- tools::file_path_sans_ext(file)
+ temp_tex_file <- paste0(tools::file_path_sans_ext(file), ".tex")
writeLines(temp_tex, temp_tex_file, useBytes = T)
system(paste0("xelatex -interaction=batchmode ", temp_tex_file))
if (!keep_tex) {
@@ -98,23 +101,22 @@
unlink(temp_file_delete)
}
- table_img_pdf <- try(magick::image_read(paste0(temp_file, ".pdf"),
- density = density),
- silent = T)
- if (class(table_img_pdf) == "try-error") {
- stop("Ghostscript is required to read PDF on windows. ",
- "Please download it here: https://ghostscript.com/")
+ if (tools::file_ext(file) != "pdf") {
+ table_img_pdf <- try(
+ magick::image_read(paste0(tools::file_path_sans_ext(file), ".pdf"),
+ density = 300), silent = T)
+ if (class(table_img_pdf) == "try-error") {
+ stop("We hit an error when trying to use magick to read the generated ",
+ "PDF file. If you are using Windows, it could be possible that you",
+ " had not installed ghostscript (https://ghostscript.com/). ",
+ "Otherwise, you may check your magick installation and try to ",
+ "use magick::image_read to read the PDF file manually. ")
+ }
+ unlink(paste0(tools::file_path_sans_ext(file), ".pdf"))
+ table_img <- magick::image_convert(table_img_pdf,
+ tools::file_ext(file))
+ magick::image_write(table_img, file)
}
- if (!keep_pdf) {
- unlink(paste0(temp_file, ".pdf"))
- }
- table_img <- magick::image_convert(table_img_pdf, file_format)
- if (!is.null(filename)) {
- temp_img <- paste0(filename, ".", file_format)
- } else {
- temp_img <- tempfile(fileext = paste0(".", file_format))
- }
- magick::image_write(table_img, temp_img)
- include_graphics(temp_img)
+ return(file)
}