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

`format_tt()` breaks when using a data frame with NULL column names and no column/row index #306

Closed andrewheiss closed 2 months ago

andrewheiss commented 2 months ago

When using format_tt() on a data frame with column names set to NULL, and without specifying an i or j in format_tt(), this error appears:

Error:
! `value` must be character.

Here's a reprex:

library(tinytable)

# This works
x <- data.frame(x = 1:5)
x |> 
  tt() |> 
  format_tt()

# This breaks
x <- data.frame(x = 1:5)
colnames(x) <- NULL
x |> 
  tt() |> 
  format_tt()

# But this works
x <- data.frame(x = 1:5)
colnames(x) <- NULL
x |> 
  tt() |> 
  format_tt(j = 1)

This might be expected behavior, but it used to work—I just stumbled on it after re-rendering a .qmd file I was working with earlier this week, where I had format_tt(escape = TRUE): https://github.com/andrewheiss/mountainous-mackerel/blob/aeb8e21dcfebc94061f4b9352f29794e468c25e8/manuscript/appendix.qmd#L529

I'm happy to specify the column index like format_tt(j = 1:ncol(x), escape = TRUE), and it fixes the error—just curious if this is an expected error.

vincentarelbundock commented 2 months ago

I'm a massive fan of assertions, because they make it clear to users why things don't work. But in this case, I was over-aggressive.

Thanks for the report! Should be fixed now.