insightsengineering / formatters

A framework for creating listings of raw data that include specialized formatting, headers, footers, referential footnotes, and pagination.
https://insightsengineering.github.io/formatters/
Other
15 stars 6 forks source link

[Bug]: toString fails when section dividers are present AND cell wrapping occurs #221

Closed gmbecker closed 9 months ago

gmbecker commented 10 months ago

The culprit is the use of x (the original input) rather than mat (the input updated upstream in the function by do_cell_fnotes_wrap) in this line. We need the updated row grouping not the original.

https://github.com/insightsengineering/formatters/blob/3178e6573d5e583e5c06846d00322392f6222131/R/tostring.R#L531

Probably good to check any other uses of throughout the function too, though the above is definately the acute problem I ran into.

repro (using rtables for convenience):

df <- data.frame(cat =c( "really long thing its so long",
                        "reasonable thing",
                        "short"),
                 value = c(6, 3, 10))

lyt <- basic_table() %>%
    split_rows_by("cat", section_div = " ") %>%
    analyze("value")

tbl <- build_table(lyt, df)

cat(toString(tbl)) # works

cw <- propose_column_widths(tbl)
cw[1] <- 11
cat(toString(tbl, widths = cw)) ## fails
Melkiades commented 10 months ago

related: