I am trying to save a kableExtra html table to .png format in R. This worked smoothly for previous versions of R, but I recently started getting an error message I cannot understand after switching to version 4.3.2. There are no regular expressions in the contents of the table so I am not sure what to make of this.

I have tried uninstalling and reinstalling kableExtra and webshot2, to no avail.

Here is an example:


library(kableExtra)

df <- data.frame(x = c(1:10), y = c(11:20))

tab <- kbl(df) |> kable_classic()

save_kable(tab, "tab.png")
  

This should save a .png image of the table, but instead I get the following error message:

Warning: TRE pattern compilation error 'Invalid back reference'Error in sub(file, "", filename) : invalid regular expression 'C:\Users\ECS155\AppData\Local\Temp\2\Rtmp0SBfQp\tab34a035bd7a3f.html', reason 'Invalid back reference'

*with full traceback: *

Error in sub(file, "", filename) : invalid regular expression 'C:\Users\ECS155\AppData\Local\Temp\2\Rtmp0SBfQp\tab34a035bd7a3f.html', reason 'Invalid back reference'

7. sub(file, "", filename)

6. file_url(x)

5. FUN(X[[i]], ...)

4. vapply(url, function(x) { if (!is_url(x)) { file_url(x) } ...

3. webshot2::webshot(file_temp_html, file, ...)

2. save_kable_html(x, file, bs_theme, self_contained, extra_dependencies, density, ...)

1. save_kable(tab, "tab.png")

Thanks in advance for your help!

1

There are 1 best solutions below

3
the-mad-statter On

Updates exist for {webshot2} (v0.1.1) that have not yet been pushed to CRAN.

Specifically this change might solve your issue.

Try installing the DEV version of {webshot2} (v0.1.1.9000) from GitHub with

devtools::install_github("rstudio/webshot2")

or

remotes::install_github("rstudio/webshot2")

or

pak::pkg_install("rstudio/webshot2")