vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
196 stars 16 forks source link

Line at the bottom of the table misplaced when grouping rows #324

Closed ahcombs closed 1 month ago

ahcombs commented 1 month ago

Hello--thank you for the phenomenal modelsummary/tinytable workflow! I'm just trying it out for coefficient table creation for the first time and I'm really appreciating the interface.

I'm using modelsummary 2.1.1 and tinytable 0.3.0.34 (though I also tried the CRAN version of tinytable, 0.3.0, with the same result). I ran into an issue with the placement of the horizontal line that separates the coefficients from the model fit statistics below. When I group rows, the line at the bottom does not shift down to accommodate the new row, and so one of the rows that should have been above it instead ends up below it. Example:

library(modelsummary)
library(tinytable)

carmod <- lm(mpg ~ as.factor(cyl), data = mtcars)

modelsummary(carmod) |> 
  group_tt(
    i = list(
      "Cyl" = 3
    )
  )  |> 
  save_tt("carmod.png")

gives the table below, where (1.299) sits below the line instead of above it. The more row groups you add, the more rows sit below the divider line. I tried manually removing the line by setting the "line" argument to NULL or the "line_color" argument to "white" in style_tt(), but this didn't work.

carmod

vincentarelbundock commented 1 month ago

Thanks for taking the time to open this issue, I appreciate it!

Good catch.

I have a pretty good sense of what's going on and an idea for how to fix this, but it's likely to be a bit tricky to implement. Also, life is crazy right now, with conferences and prep for the coming semester, so I might not get to this immediately. I'll ping you as soon as there's a fix.

Cheers

ahcombs commented 1 month ago

Awesome; thank you for your quick reply!

vincentarelbundock commented 1 month ago

So I thought about this a bit, and it turns out to be harder than I thought. The problem is that modelsummary() hard-codes the location of the line before tinytable adds the new row. And there's really no way for modelsummary() to be able to anticipate that the user will later add some rows by post-processing.

So the only solution I can think of requires a little bit of manual handling by the user. I documented it here:

https://modelsummary.com/vignettes/appearance.html#starting-fresh

I'll keep thinking about it, but that might be the only (sub-optimal) solution for a while...

ahcombs commented 2 weeks ago

Good enough for me—thanks so much!

On Aug 16, 2024, at 5:59 PM, Vincent Arel-Bundock @.***> wrote:

So I thought about this a bit, and it turns out to be harder than I thought. The problem is that modelsummary() hard-codes the location of the line before tinytable adds the new row. And there's really no way for modelsummary() to be able to anticipate that the user will later add some rows by post-processing.

So the only solution I can think of requires a little bit of manual handling by the user. I documented it here:

https://modelsummary.com/vignettes/appearance.html#starting-fresh

I'll keep thinking about it, but that might be the only (sub-optimal) solution for a while...

— Reply to this email directly, view it on GitHub https://github.com/vincentarelbundock/tinytable/issues/324#issuecomment-2293763381, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFP2AXIYOEBNYAGXRFI2UTTZRYOVTAVCNFSM6AAAAABMSGPEZ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTG43DGMZYGE. You are receiving this because you authored the thread.