bump version...
remove magick from imports to suggests;
update documentation
update vignettes
diff --git a/R/column_spec.R b/R/column_spec.R
index 97dcd06..ffd23d5 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -26,14 +26,13 @@
#' in a character string for the CSS of the border line
#'
#' @examples x <- knitr::kable(head(mtcars), "html")
-#' column_spec(x, 1, width = "20em", bold = TRUE, italic = TRUE)
+#' column_spec(x, 1:2, width = "20em", bold = TRUE, italic = TRUE)
#'
#' @export
column_spec <- function(kable_input, column,
width = NULL, bold = FALSE, italic = FALSE,
monospace = FALSE, color = NULL, background = NULL,
- border_left = FALSE, border_right = FALSE,
- ...) {
+ border_left = FALSE, border_right = FALSE) {
if (!is.numeric(column)) {
stop("column must be numeric. ")
}
@@ -52,7 +51,7 @@
return(column_spec_latex(kable_input, column, width,
bold, italic, monospace,
color, background,
- border_left, border_right, ...))
+ border_left, border_right))
}
}
@@ -130,8 +129,7 @@
column_spec_latex <- function(kable_input, column, width,
bold, italic, monospace,
color, background,
- border_left, border_right,
- decimal_align = F) {
+ border_left, border_right) {
table_info <- magic_mirror(kable_input)
if (!is.null(table_info$collapse_rows)) {
message("Usually it is recommended to use column_spec before collapse_rows,",
diff --git a/R/kableExtra-package.R b/R/kableExtra-package.R
index 2664c4d..5add5e5 100644
--- a/R/kableExtra-package.R
+++ b/R/kableExtra-package.R
@@ -66,7 +66,6 @@
#' @importFrom magrittr %>%
#' @importFrom utils read.csv
#' @importFrom readr read_lines read_file write_file
-#' @import magick
#' @name kableExtra-package
#' @aliases kableExtra
#' @docType package
diff --git a/R/kable_as_image.R b/R/kable_as_image.R
index 6a83118..044943c 100644
--- a/R/kable_as_image.R
+++ b/R/kable_as_image.R
@@ -31,54 +31,65 @@
#' `c("\\usepackage{threeparttable}", "\\usepackage{icons}")`
#' @param keep_pdf A T/F option to control if the mid-way standalone pdf should
#' be kept. Default is `FALSE`.
+#' @param density Resolution to read the PDF file. Default value is 300, which
+#' should be sufficient in most cases.
#'
#' @export
kable_as_image <- function(kable_input, filename = NULL,
file_format = "png",
latex_header_includes = NULL,
- keep_pdf = FALSE) {
- temp_tex <- c(
- "\\documentclass[border=1mm, preview]{standalone}",
- "\\usepackage[active,tightpage]{preview}",
- "\\usepackage{varwidth}",
- "\\usepackage{amssymb, amsmath}",
- "\\usepackage{ifxetex,ifluatex}",
- "\\usepackage{fixltx2e}",
- "\\usepackage{polyglossia}",
- "\\setmainlanguage{$mainlang$}",
- latex_pkg_list(),
- "\\usepackage{graphicx}",
- "\\usepackage{mathspec}",
- "\\usepackage{xltxtra,xunicode}",
- latex_header_includes,
- "\\begin{document}",
- enc2utf8(as.character(kable_input)),
- "\\end{document}"
- )
- temp_tex <- paste(temp_tex, collapse = "\n")
- temp_file <- paste0("table_", format(Sys.time(), "%Y-%m-%d_%H%M%S"))
- write_file(temp_tex, paste0(temp_file, ".tex"))
- system(paste0("xelatex -interaction=batchmode ", temp_file, ".tex"))
- temp_file_delete <- paste0(temp_file, c(".tex", ".aux", ".log"))
- unlink(temp_file_delete)
-
- table_img_pdf <- try(image_read(paste0(temp_file, ".pdf"), density = 300),
- 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 (!keep_pdf) {
- unlink(paste0(temp_file, ".pdf"))
- }
- table_img <- image_convert(table_img_pdf, file_format)
- if (!is.null(filename)) {
- temp_img <- paste0(filename, ".", file_format)
+ keep_pdf = FALSE,
+ density = 300) {
+ if (!requireNamespace("magick", quietly = TRUE)) {
+ stop('kable_as_image requires the magick package, which is not available ',
+ 'on all platforms. Please get it installed ',
+ 'via install.packages("magick"). If you are running on Windows, you ',
+ 'also need to install Ghostscript. Please download it here:',
+ 'https://ghostscript.com/')
} else {
- temp_img <- tempfile(fileext = paste0(".", file_format))
- }
- image_write(table_img, temp_img)
+ temp_tex <- c(
+ "\\documentclass[border=1mm, preview]{standalone}",
+ "\\usepackage[active,tightpage]{preview}",
+ "\\usepackage{varwidth}",
+ "\\usepackage{amssymb, amsmath}",
+ "\\usepackage{ifxetex,ifluatex}",
+ "\\usepackage{fixltx2e}",
+ "\\usepackage{polyglossia}",
+ "\\setmainlanguage{$mainlang$}",
+ latex_pkg_list(),
+ "\\usepackage{graphicx}",
+ "\\usepackage{mathspec}",
+ "\\usepackage{xltxtra,xunicode}",
+ latex_header_includes,
+ "\\begin{document}",
+ enc2utf8(as.character(kable_input)),
+ "\\end{document}"
+ )
+ temp_tex <- paste(temp_tex, collapse = "\n")
+ temp_file <- paste0("table_", format(Sys.time(), "%Y-%m-%d_%H%M%S"))
+ write_file(temp_tex, paste0(temp_file, ".tex"))
+ system(paste0("xelatex -interaction=batchmode ", temp_file, ".tex"))
+ temp_file_delete <- paste0(temp_file, c(".tex", ".aux", ".log"))
+ unlink(temp_file_delete)
- include_graphics(temp_img)
- return(kable_input)
+ 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 (!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)
+ }
}
diff --git a/R/row_spec.R b/R/row_spec.R
index 5a77ee4..3cd4808 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -19,7 +19,7 @@
#' pay attention to the differences in color codes between HTML and LaTeX.
#'
#' @examples x <- knitr::kable(head(mtcars), "html")
-#' row_spec(x, 1, bold = TRUE, italic = TRUE)
+#' row_spec(x, 1:2, bold = TRUE, italic = TRUE)
#'
#' @export
row_spec <- function(kable_input, row,