Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Report: <tbl_cross(margin = "col") incompatible with add_p(source_note = TRUE)> #1520

Closed
meenakshi-kushwaha opened this issue Jun 2, 2023 · 1 comment · Fixed by #1531

Comments

@meenakshi-kushwaha
Copy link

meenakshi-kushwaha commented Jun 2, 2023


Hello, Thank you for the very useful package!
As in the reprex below when I specify margin = "col" in tbl_cross() followed by add_p(source_note = TRUE) in an Rmd document I get the following error when knitting into word document. The code chunk runs fine by itself but I get this error when trying to knit the document. I can remedy the error by removing margin = col or by removing source_note = TRUE . But I would love to use both options together for a custom cross_table.

error

"
Error in data.frame():
! arguments imply differing number of rows: 3, 4
Backtrace:

  1. rmarkdown::render(...)
  2. flextable::footnote(...)
  3. base::data.frame(i = i, j = j)
    Execution halted"

reprex (Rmd script)


output:
word_document: default

library(gtsummary)
library(dplyr)
mtcars %>% 
  tbl_cross(row = vs, col = am,
            margin = "col") %>% 
  add_p(source_note = TRUE) 

Screen Shot 2023-06-02 at 11 25 12 PM
@ddsjoberg
Copy link
Owner

Thank you @meenakshi-kushwaha for the bug report!

The issue arises when converting the gtsummary table to a flextable format.

  • flextable is the default printer for R markdown Word output
  • I don't think flextable supports source notes in the same way gt does....so despite the bug, I don't think you'd see the source note after it's been converted to flextable
  • BUT the latest gt release (v0.9.0) has wonderful support for Word tables
  • Add gtsummary::theme_gtsummary_printer("gt") to the top of your script to override a flextable print and print with gt instead.

I'll fix this bug, but in the meantime, I hope this solution will work. Let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants