hughjonesd / huxtable

An R package to create styled tables in multiple output formats, with a friendly, modern interface.
http://hughjonesd.github.io/huxtable
Other
321 stars 28 forks source link

Table caption is missing in docx output #120

Closed sjewo closed 4 years ago

sjewo commented 4 years ago

Describe the bug Table captions are missing in docx documents, because the attributes is not set in as_flextable().

Minimal Reproducible Example Create a Rmd file:

---
output: word_document
---

```{r}
library(huxtable)
ht <- hux(
        Employee = c('John Smith', 'Jane Doe', 'David Hugh-Jones'),
        Salary = c(50000, 50000, 40000),
        add_colnames = TRUE
      )
ht <- set_caption(ht, "Table 1: A caption")
ht

Expected behavior There should be a caption in the docx document.

I added some code to get a caption in this branch: caption branch in sjewo/huxtable.

FYI: quick_docxwill strip the caption anyway.

System details

huxtable 4.7.0.9000

hughjonesd commented 4 years ago

The branch looks good, can you make a pull request?

Do you know why quick_docx strips the caption?

hughjonesd commented 4 years ago

One other small thing - can you include a check for flextable version >= 0.5.5? This is when set_caption was introduced.

sjewo commented 4 years ago

Hi there, I will add the check for the minimum flextable version tomorrow and create a pull request afterwards.

As I understood, the caption is not part of the table and will be added in the knit_print function of flextable: https://github.com/davidgohel/flextable/blob/fba70c8c338186ceb16f3e0310988a7c68dac854/R/printers.R#L212

hughjonesd commented 4 years ago

Tricky. I'll edit the documentation to reflect that.

sjewo commented 4 years ago

I'll added some code to include captions in quick_docx() and added the checks. Pull request is on its way.

hughjonesd commented 4 years ago

This should now work.