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

apply_footnote_plan can't differentiate between generic footnotes and source footnotes #459

Open
crystalluckett-sanofi opened this issue Apr 17, 2024 · 0 comments

Comments

@crystalluckett-sanofi
Copy link

Footnotes without a designated location are applied via gt::tab_source_note, which does not allow for generic footnotes to appear prior to footnotes with defined locations.

For example,

tfrmt <- tfrmt::tfrmt(
  label = label,
  column = column,
  param = param,
  body_plan = tfrmt::body_plan(
    tfrmt::frmt_structure(
      group_val = ".default",
      label_val = ".default",
      tfrmt::frmt_combine(
        "{count} {percent}",
        count = tfrmt::frmt("xxx"),
        percent = tfrmt::frmt_when(
          "==100" ~ tfrmt::frmt(""), 
          "==0" ~ "",
          "TRUE" ~ tfrmt::frmt("(xx.x%)")
        )
      )
    )
  )
) 
tfrmt::tfrmt(
  tfrmt,
  footnote_plan = tfrmt::footnote_plan(
    tfrmt::footnote_structure("BMI: Body Mass Index"),
    tfrmt::footnote_structure(
      "Placebo drug + standard of care",
      column_val = "column2"
    ),
    tfrmt::footnote_structure("Source Note")
  )
) |> 
  tfrmt::print_mock_gt()

image

This occurs because footnote structures without defined locations are automatically applied as source notes

if(length(loc$row)==0 && length(loc$col)==0){
gt <- gt %>%
tab_source_note(loc$note)

Whereas if I were to apply the footnotes to the gt object manually as desired, I can get the desired output:

tfrmt::print_mock_gt(tfrmt) |> 
  gt::tab_footnote("BMI: Body Mass Index") |> 
  gt::tab_footnote(
    "Placebo drug + standard of care",
    locations = gt::cells_column_labels(
      columns = all_of(
        as.character("column2")
      )
    )
  ) |> 
  gt::tab_source_note("Source Note")

image

I think a simple fix would be to add a new argument to footnote_structure, source, which is TRUE for source notes and FALSE otherwise.
When source == TRUE and there's no location, then call gt::tab_footnote. Otherwise, use gt::tab_source_note as is.

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

No branches or pull requests

1 participant