Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_image

Render the table as an format-independent image and use it in rmarkdown


Description

This function generates a temporary png file using save_kable and then try to put it in an rmarkdown document using knitr::include_graphics.

Usage

as_image(x, width = NULL, height = NULL, file = NULL, ...)

Arguments

x

kable input. Either HTML or LaTeX

width

Image width in inches. (1 inch = 2.54 cm)

height

Image height in inches. (1 inch = 2.54 cm)

file

By default, as_image saves to an temp file, which works for normal rmarkdown. However if you are using things like xaringan, which can't be a standalone html, you can specify this file be the path you need, eg. "img/something.png"

...

Additional arguments passed to save_kable.

Examples

## Not run: 
library(kableExtra)

kable(mtcars, "latex", booktabs = T) %>%
kable_styling(latex_options = c("striped", "scale_down")) %>%
row_spec(1, color = "red") %>%
as_image()

## End(Not run)

kableExtra

Construct Complex Table with 'kable' and Pipe Syntax

v1.3.4
MIT + file LICENSE
Authors
Hao Zhu [aut, cre] (<https://orcid.org/0000-0002-3386-6076>), Thomas Travison [ctb], Timothy Tsai [ctb], Will Beasley [ctb], Yihui Xie [ctb], GuangChuang Yu [ctb], Stéphane Laurent [ctb], Rob Shepherd [ctb], Yoni Sidi [ctb], Brian Salzer [ctb], George Gui [ctb], Yeliang Fan [ctb], Duncan Murdoch [ctb], Bill Evans [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.