rkableextramodelsummarytinytable

"Argument is of length zero" from kableExtra after updating Rstudio


After I updated Rstudio some code that had previously worked fine now throws an error. I've confirmed that this isn't due to the nature of my data by using mtcars for the same thing and getting the same error. I've tried updating the package, both from CRAN and GitHub, to no avail.

I've included a code example, and also attached a screenshot in case the issue is idiosyncratic to my machine. I'm running the latest versions of both R and Rstudio.

library(modelsummary)
library(kableExtra)
library(tidyverse)

# Create some example data and fit a model
data(mtcars)
model <- lm(mpg ~ cyl + hp, data = mtcars)

# Generate the model summary using kable as the output format
table_output <- modelsummary(model, output = "latex", stars = TRUE, title = "Model Summary")

# Style the table with kable_styling and add headers

#this is where I run into the problem
styled_table <- table_output %>%
    add_header_above(c(" " = 1, "Model Results" = 2)) %>%
    kable_styling(latex_options = "scale_down")



Screenshot of error


Solution

  • Please read the warning printed when calling library(modelsummary), as shown below. The 2.0.0 version of that package now uses tinytable instead of kableExtra. If you really want to switch back to kableExtra, you can do so by following the instructions in the startup message.

    However, I personally recommend that you give tinytable a try, as it was specifically designed to work well with modelsummary. (Both packages are developed by me.) Here are the equivalent commands to what you were trying to do:

    library(tinytable)
    library(modelsummary)
    
    `modelsummary` 2.0.0 now uses `tinytable` as its default table-drawing
    backend. Learn more at: https://vincentarelbundock.github.io/tinytable/
    
    Revert to `kableExtra` for one session:
    
    options(modelsummary_factory_default = 'kableExtra')
    
    Change the default backend persistently:
    
    config_modelsummary(factory_default = 'gt')
    
    Silence this message forever:
    
    config_modelsummary(startup_message = FALSE)
    
    model <- lm(mpg ~ cyl + hp, data = mtcars)
    modelsummary(model, output = "latex", stars = TRUE, title = "Model Summary") |>
        group_tt(j = list("Model Results" = 2)) |>
        theme_tt("resize")
    

    enter image description here