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: as_flex_table doesn't pass multi-column/row footnote coordinates correctly #2062

Open
geneh0 opened this issue Nov 8, 2024 · 1 comment · May be fixed by #2063
Open

Bug Report: as_flex_table doesn't pass multi-column/row footnote coordinates correctly #2062

geneh0 opened this issue Nov 8, 2024 · 1 comment · May be fixed by #2063
Milestone

Comments

@geneh0
Copy link

geneh0 commented Nov 8, 2024

I want to add footnotes throughout all levels of a variable and across a couple columns. Then I want to convert it to a flextable. I get an error at the as_flex_table stage.

I think it's because during the creation of the flextable, (something that creates flextable_calls) it tries to create footnotes that reference at all permutations of i and j. However, flextable uses the pairwise combination of i and j:

flextable::footnotes

Symbols are added to the cells designated by the selection i and j. If you use i = c(1,3) and j = c(2,5), then you will add the symbols (or the repeated symbol) to cells [1,2] and [3,5].

In addition to the example error below, I'm noticing that some other tables will only have flextable footnotes in alternating rows because of the way i and j are expanded.

library(dplyr)
library(gtsummary)

trial %>% 
  tbl_summary(by = trt, 
              include = c(age,
                          stage,
                          grade)) %>% 
  modify_table_styling(columns = c(stat_1, stat_2),
                       rows = (variable %in% "grade") & (row_type == "level"),
                       footnote = "Cell-level foonotes here.") %>% 
  as_flex_table()
#> Error in data.frame(i = i, j = j): arguments imply differing number of rows: 3, 2

Created on 2024-11-08 with reprex v2.1.1

When debugging as_flex_table

Browse[2]> flextable_calls$footnote
[[1]]
flextable::footnote(i = 1L, j = 2:3, value = flextable::as_paragraph("Median (IQR); n (%)"), 
    part = "header", ref_symbols = 1L)

[[2]]
flextable::footnote(i = 9:11, j = 2:3, value = flextable::as_paragraph("Cell-level foonotes here."), 
    part = "body", ref_symbols = 2L)
ddsjoberg added a commit that referenced this issue Nov 9, 2024
@ddsjoberg ddsjoberg linked a pull request Nov 9, 2024 that will close this issue
11 tasks
@ddsjoberg
Copy link
Owner

Thank you for the report and the reprex! I am surprised this hasn't been reported long ago...these lines of code haven't been touched in years. Much appreciated! This should be addressed in #2063

@ddsjoberg ddsjoberg added this to the v2.1.0 milestone Nov 13, 2024
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