kableExtra (version 0.9.0)

kable_as_image: Convert a LaTeX table to an image and place it in a rmarkdown document

Description

This is a LaTeX-only function. This function will render the raw LaTeX code (could be codes generated by other table packages like xtable) to generate a table, convert it to an image and put it back to a rmarkdown environment. It is a "better than nothing" solution to print high quality tables in rmarkdown Word document. By using this, you need to take the responsibility of explaining to your collaborators why they can't make edits to the tables in Word.

Also, if a filename is provided, user has the option to "save" the table to an image file like ggplot2::ggsave().

Note that, if you are using this function on a Windows computer, you need to install Ghostscript before you can use this feature. It is essential for magick to read PDFs on Windows. Website for Ghostscript: https://ghostscript.com/

The idea of this function was coming from this StackOverflow question. The approach was learned and adopted from the texpreview package, which allows you to preview the results of TeX code in the Viewer panel.

Usage

kable_as_image(kable_input, filename = NULL, file_format = "png",
  latex_header_includes = NULL, keep_pdf = FALSE, density = 300,
  keep_tex = FALSE)

Arguments

kable_input

Raw LaTeX code to generate a table. It doesn't have to came from kable or kableExtra.

filename

Character String. If specified, the image will be saved under the specified (path &) name. You don't need to put file format like ".png" here.

file_format

Character String to specify image format, such as png, jpeg, gif, tiff, etc. Default is png.

latex_header_includes

A character vector of extra LaTeX header stuff. Each element is a row. You can have things like c("\\usepackage{threeparttable}", "\\usepackage{icons}")

keep_pdf

A T/F option to control if the mid-way standalone pdf should be kept. Default is FALSE.

density

Resolution to read the PDF file. Default value is 300, which should be sufficient in most cases.

keep_tex

A T/F option to control if the latex file that is initially created should be kept. Default is FALSE.