Skip to contents

Saves a gt table to a temporary png image file and uses magick to render tables in reproducible examples like reprex::reprex() or in package function examples (see details for further information).

Usage

gt_render_image(gt_tbl, ...)

Arguments

gt_tbl

An object of class gt_tbl usually created by gt::gt()

...

Arguments passed on to webshot2::webshot() and par().

Value

Returns NULL invisibly.

Details

Rendering gt tables in function examples is not trivial because of the behavior of an underlying dependency: chromote. It keeps a process running even if the chromote session is closed. Unfortunately, this causes R CMD Check errors related to open connections after example runs. The only way to avoid this is setting the environment variable _R_CHECK_CONNECTIONS_LEFT_OPEN_ to "false". How to do that depends on where and how developers check their package. A good way to prevent an example from being executed because the environment variable was not set to "false" can be taken from the source code of this function.

Examples

tbl <- gt::gt_preview(mtcars)
gt_render_image(tbl)
#> file:////tmp/RtmplkdsD1/file1fba76ed1114.html screenshot completed
#> Error in if (!grepl("screenshot completed", output)) print(output): argument is of length zero