Hao Zhu | 2a64dc6 | 2017-08-28 10:57:57 -0400 | [diff] [blame] | 1 | % Generated by roxygen2: do not edit by hand |
| 2 | % Please edit documentation in R/kable_as_image.R |
| 3 | \name{kable_as_image} |
| 4 | \alias{kable_as_image} |
| 5 | \title{Convert a LaTeX table to an image and place it in a rmarkdown document} |
| 6 | \usage{ |
| 7 | kable_as_image(kable_input, filename = NULL, file_format = "png", |
Hao Zhu | 68b5bbf | 2018-03-26 11:30:34 -0400 | [diff] [blame] | 8 | latex_header_includes = NULL, keep_pdf = FALSE, density = 300, |
| 9 | keep_tex = FALSE) |
Hao Zhu | 2a64dc6 | 2017-08-28 10:57:57 -0400 | [diff] [blame] | 10 | } |
| 11 | \arguments{ |
| 12 | \item{kable_input}{Raw LaTeX code to generate a table. It doesn't have to |
| 13 | came from \code{kable} or \code{kableExtra}.} |
| 14 | |
| 15 | \item{filename}{Character String. If specified, the image will be saved under |
| 16 | the specified (path &) name. You don't need to put file format like ".png" |
| 17 | here.} |
| 18 | |
| 19 | \item{file_format}{Character String to specify image format, such as \code{png}, |
| 20 | \code{jpeg}, \code{gif}, \code{tiff}, etc. Default is \code{png}.} |
| 21 | |
| 22 | \item{latex_header_includes}{A character vector of extra LaTeX header stuff. |
| 23 | Each element is a row. You can have things like |
antaldaniel | bfaf703 | 2018-05-30 21:55:18 +0200 | [diff] [blame^] | 24 | \code{c("\\\\usepackage{threeparttable}", "\\\\usepackage{icons}")} You could |
| 25 | probably add your language package here if you use non-English text in your |
| 26 | table, such as \code{\\\\usepackage[magyar]{babel}}.} |
Hao Zhu | 2a64dc6 | 2017-08-28 10:57:57 -0400 | [diff] [blame] | 27 | |
| 28 | \item{keep_pdf}{A T/F option to control if the mid-way standalone pdf should |
| 29 | be kept. Default is \code{FALSE}.} |
Hao Zhu | 4840bc9 | 2017-09-15 15:55:05 -0400 | [diff] [blame] | 30 | |
| 31 | \item{density}{Resolution to read the PDF file. Default value is 300, which |
| 32 | should be sufficient in most cases.} |
Hao Zhu | 68b5bbf | 2018-03-26 11:30:34 -0400 | [diff] [blame] | 33 | |
| 34 | \item{keep_tex}{A T/F option to control if the latex file that is initially created |
| 35 | should be kept. Default is \code{FALSE}.} |
Hao Zhu | 2a64dc6 | 2017-08-28 10:57:57 -0400 | [diff] [blame] | 36 | } |
| 37 | \description{ |
| 38 | This is a LaTeX-only function. This function will render the |
| 39 | raw LaTeX code (could be codes generated by other table packages like |
| 40 | \code{xtable}) to generate a table, convert it to an image and put it back to a |
| 41 | rmarkdown environment. It is a "better than nothing" solution to print high |
| 42 | quality tables in rmarkdown Word document. By using this, you need to take |
Hao Zhu | 245931c | 2017-09-01 22:43:56 -0400 | [diff] [blame] | 43 | the responsibility of explaining to your collaborators why they can't make |
Hao Zhu | a9c43dc | 2017-09-04 23:00:39 -0400 | [diff] [blame] | 44 | edits to the tables in Word. |
Hao Zhu | 2a64dc6 | 2017-08-28 10:57:57 -0400 | [diff] [blame] | 45 | |
| 46 | Also, if a filename is provided, user has the option to "save" the table to |
| 47 | an image file like \code{ggplot2::ggsave()}. |
| 48 | |
Hao Zhu | 246b95c | 2017-09-14 14:29:48 -0400 | [diff] [blame] | 49 | Note that, if you are using this function on a Windows computer, you need |
| 50 | to install Ghostscript before you can use this feature. It is essential for |
| 51 | magick to read PDFs on Windows. Website for Ghostscript: https://ghostscript.com/ |
| 52 | |
Hao Zhu | 2a64dc6 | 2017-08-28 10:57:57 -0400 | [diff] [blame] | 53 | The idea of this function was coming from \href{https://stackoverflow.com/questions/44711313/save-rmarkdowns-report-tables-and-figures-to-file}{this StackOverflow question}. |
| 54 | The approach was learned and adopted from the \href{https://github.com/metrumresearchgroup/texPreview}{texpreview} |
| 55 | package, which allows you to preview the results of TeX code in the Viewer panel. |
| 56 | } |