flextime output is strange and is stripping caption.

I have been playing with {flextime] and I am getting some weird results.

If I do


library(flextable)
tab1 <- flextable(head(iris, 20)) |> 
            set_caption("Truncated Iris Data Set")

Then the preview in R is as expected.

But if I do

save_as_image(tab1, "tab1.png")

I am getting some strange results. The caption is getting stripped and in Image Viewer I getting this though ksnip is reading it clearly but with no caption.

The image, without caption in loading okay in Quarto

Any suggestions about what is happening?

R version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8
[4] LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

time zone: America/New_York
tzcode source: system (glibc)

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] flextable_0.9.5

loaded via a namespace (and not attached):
[1] jsonlite_1.8.8 compiler_4.3.3 crayon_1.5.2
[4] promises_1.2.1 zip_2.3.1 Rcpp_1.0.12
[7] xml2_1.3.6 stringr_1.5.1 later_1.3.2
[10] fontquiver_0.2.1 textshaping_0.3.7 systemfonts_1.0.6
[13] uuid_1.2-0 fastmap_1.1.1 mime_0.12
[16] R6_2.5.1 lobstr_1.1.2 gfonts_0.2.0
[19] pak_0.7.2 gdtools_0.3.7 curl_5.2.1
[22] knitr_1.45 openssl_2.1.1 crul_1.4.0
[25] shiny_1.8.0 rlang_1.1.3 httpcode_0.3.0
[28] stringi_1.8.3 xfun_0.42 httpuv_1.6.14
[31] cli_3.6.2 magrittr_2.0.3 digest_0.6.35
[34] grid_4.3.3 rstudioapi_0.15.0 xtable_1.8-4
[37] askpass_1.2.0 lifecycle_1.0.4 pryr_0.1.6
[40] evaluate_0.23 glue_1.7.0 data.table_1.15.2
[43] officer_0.6.5 fontLiberation_0.1.0 ragg_1.3.0
[46] codetools_0.2-19 fontBitstreamVera_0.1.1 rmarkdown_2.26
[49] tools_4.3.3 ellipsis_0.3.2 htmltools_0.5.7

Likely it's a bug. I reproduced your results. The stored image seems to have a transparent background, which is more like an SVG image than a PNG image. If I try to save it to an SVG file, I get an error message, suggesting another bug.

Interesting, I get an .svg file that looks like the .png file. It open nicely in Inkscape but Quarto tells me I need rsvg-convert to process it.

Looks like a bug. What's the best way to report it? I was starting to get very fond of {flextable} after just a few hours messing about.

Thanks

The developer of the package has it on GitHub, and the issue tracker is at Issues · davidgohel/flextable · GitHub.

Thanks, issue #616 filed.

Reply from the developer. David Gohel

A caption is typically placed above the table, and it is not part of the table itself. This means that when you export a table to PNG/SVG, the caption will not be included. Captions are for Word/HTML/PDF outputs, i.e. tables located in documents. pptx and images don't have captions.

Problem solved.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.