rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.03k stars 208 forks source link

Add ICML export format to `gtsave()` #1451

Open elipousson opened 1 year ago

elipousson commented 1 year ago

Prework

Proposal

I use gt in combination with Microsoft Word to created formatted documents in InDesign. While I have been using the Microsoft Word export format (in combination with the gto package), the import from Microsoft Word to InDesign does not support column spans and the styles for individual parts of the table are not preserved as paragraph or character styles—so there is a a fair amount of manual reformatting required after importing the table.

The alternative option that I'm suggesting would be an export to a ICML format (or potentially a tagged XML file that could work with InDesign's support for XML import).

I already explored a few different work arounds without success. For example, here is a minimal example showing a basic option for converting from the HTML output to an ICML file:

library(gt)

gtsave_icml <- function(data, filename) {
  filename_html <- gsub(".icml$", ".html", filename)

  gt::gtsave(data, filename_html)

  rmarkdown::pandoc_convert(
    input = filename_html,
    output = filename,
    options = "--standalone"
  )
}

tbl <- exibble |> gt()

gtsave_icml(tbl, "gt-tbl.icml")

Created on 2023-10-02 with reprex v2.0.2

Unfortunately, the Pandoc ICML Writer does not currently support many of the rich table formatting options that make gt tables so nice! This issue is documented here: https://github.com/jgm/pandoc/issues/6615

I also attempted to convert the HTML file into an XML file (similar to the process outlined in this 2014 post) but InDesign supports style mapping to tags—not based on class attributes—so it still doesn't resolve the issue.

I understand that InDesign is not as widely used as many of the other export formats but I figured I'd submit the issue just in case it could be included in a long-term roadmap or if any other users have encountered this challenge and may have some suggestions to try. If anyone else want to take this on, the syntax for tables in InDesign is documented here: https://carijansen.com/indesign-xml-reference-guide/

steveputman commented 1 year ago

+1 here, also understanding that we're probably the marginal case. @elipousson I made some lazy attempts back in the early days of gt but also hit a wall with pandoc.