hughjonesd / huxtable

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

Bug Report: Error with Word output when mixing a blank cell in `insert_row()` with `set_markdown()` #219

Closed ddsjoberg closed 2 years ago

ddsjoberg commented 2 years ago

Hey hey!

A user of gtsummary encountered an error when they specified a blank column header with Word output.

The header row is added with with insert_row(), and that is followed by set_markdown() and the error occurs in set_markdown().

Here's an example, thanks!

---
output: word_document
---

```{r}
library(gtsummary)
tbla <- 
  trial %>%
  select(trt) %>%
  tbl_summary()
tbla$table_body %>%
  dplyr::select(label, stat_0) %>%
  huxtable::as_huxtable(add_colnames = FALSE) %>%
  huxtable::insert_row(after = 0, label = "", stat_0 = "**N = 200**") %>%
  huxtable::set_markdown(
    row = 1L, col = huxtable::everywhere,
    value = TRUE
  )

This is the error:

Quitting from lines 15-23 (reprex_huxtable.Rmd) Error in rep(list(flatten_branch), n) : invalid 'times' argument Calls: ... lapply -> flatten_ast -> -> map -> list2 Execution halted

hughjonesd commented 2 years ago

OK, this comes if you call ftExtra::as_paragraph_md(cell, .from = "commonmark+strikeout") with an empty cell. Seems like a bug in ftExtra, I'll head over there.

hughjonesd commented 2 years ago

The workaround for now would be to replace the last line with:

 huxtable::set_markdown(
    row = 1L, col = 2L,
    value = TRUE
  )

or more generally, only use set_markdown on non-empty cells.

hughjonesd commented 2 years ago

Fixed in ftExtra.