Linus
Linus

Reputation: 1

Export latex code from modelsummary using kableExtra

I am trying to get the latex code from a table that I create with modelsummary and then edit with kableExtra. I know this used to work in the past, but the newer version of modelsummary does not seem to support anymore. I think the main issue is the switch from kableExtra to tinytable as deafault table editor by modelsummary, but I think it still should somehow work the same.

I know that the following code used to work in the past:

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

model1 <- lm(y1 ~ x, data)
model2 <- lm(y2 ~ x, data)

models <- 
list(model1, model2)

table <-
  modelsummary(models,
             output = "latex")

latex_table <- table %>%
kableExtra::kable_styling(latex_options = "basic")

cat(latex_table)

However, I get the follwing error message when trying to pass the modelsummary object to kableExtra:

Error in as.data.frame.default(x) : 
  cannot coerce class ‘structure("tinytable", package = "tinytable")’ to a data.frame

Using the recommended config_modelsummary(factory_default = "kableExtra") does not solve the problem and I still get the same error message.

Is there a way to still make this work with the newer version of modelsummary still using kableExtra instead of tinytable?

Upvotes: 0

Views: 145

Answers (1)

Vincent
Vincent

Reputation: 17823

Please read the warning message printed every time the latest version (2.1.1) of modelsummary is loaded:

`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')
  options(modelsummary_factory_latex = 'kableExtra')
  options(modelsummary_factory_html = 'kableExtra')

Silence this message forever:

  config_modelsummary(startup_message = FALSE)

Upvotes: 0

Related Questions