vincentarelbundock / modelsummary

Beautiful and customizable model summaries in R.
http://modelsummary.com
Other
896 stars 74 forks source link

`tinytable` not turning off with `latex_tabular` after `config_modelsummary(factory_default = "kableExtra")` #762

Closed chickymonkeys closed 2 months ago

chickymonkeys commented 2 months ago

Hi there,

I have been hitting my head on this for some hours and I cannot really figure it out. I would like to have old behaviour of modelsummary back, avoiding drawing tables tinytable and the tabularray package when exporting in LaTeX. I have set as indicated in the changelog for 2.0.0 config_modelsummary(factory_default = "kableExtra") but, while when setting output = "latex" it correctly draws a tabular table instead of a tabularray's one, when setting output = "latex_tabular" it keeps drawing with tabularray.

Reproducible example:

library(modelsummary)
library(fixest)
options(modelsummary_format_numeric_latex = "plain")

results <- list(
  feols(mpg ~ cyl, data = mtcars),
  feols(mpg ~ cyl + hp, data = mtcars)
)
msummary(results, output = "latex_tabular")
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=c,},
column{3}={halign=c,},
hline{8}={1,2,3}{solid, 0.05em, black},
}                     %% tabularray inner close
\toprule
& (1) & (2) \\ \midrule %% TinyTableHeader
(Intercept) & 37.885  & 36.908  \\
& (2.074) & (2.191) \\
cyl         & -2.876  & -2.265  \\
& (0.322) & (0.576) \\
hp          &         & -0.019  \\
&         & (0.015) \\
Num.Obs.    & 32      & 32      \\
R2          & 0.726   & 0.741   \\
R2 Adj.     & 0.717   & 0.723   \\
AIC         & 167.3   & 167.6   \\
BIC         & 170.2   & 172.0   \\
RMSE        & 3.10    & 3.02    \\
Std.Errors  & IID     & IID     \\
\bottomrule
\end{tblr} 
msummary(results, output = "latex")
\begin{table}
\centering
\begin{tabular}[t]{lcc}
\toprule
  & (1) & (2)\\
\midrule
(Intercept) & 37.885 & 36.908\\
 & (2.074) & (2.191)\\
cyl & -2.876 & -2.265\\
 & (0.322) & (0.576)\\
hp &  & -0.019\\
 &  & (0.015)\\
\midrule
Num.Obs. & 32 & 32\\
R2 & 0.726 & 0.741\\
R2 Adj. & 0.717 & 0.723\\
AIC & 167.3 & 167.6\\
BIC & 170.2 & 172.0\\
RMSE & 3.10 & 3.02\\
Std.Errors & IID & IID\\
\bottomrule
\end{tabular}
\end{table}

sessionInfo():

R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.12.0 
LAPACK: /usr/lib/liblapack.so.3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Copenhagen
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] fixest_0.12.0        modelsummary_2.0.0.8

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.8       compiler_4.4.0       renv_1.0.3           Rcpp_1.0.12          tinytable_0.2.1.15   xml2_1.3.6           stringr_1.5.1        systemfonts_1.0.6    scales_1.3.0         fastmap_1.1.1        lattice_0.22-6       R6_2.5.1            
[13] tables_0.9.25        generics_0.1.3       Formula_1.2-5        knitr_1.46           backports_1.4.1      checkmate_2.3.1      kableExtra_1.4.0     munsell_0.5.1        insight_0.19.10.3    svglite_2.1.3        rlang_1.1.3          stringi_1.8.3       
[25] performance_0.11.0.8 xfun_0.43            parameters_0.21.6.6  stringmagic_1.1.1    datawizard_0.10.0    viridisLite_0.4.2    cli_3.6.2            magrittr_2.0.3       digest_0.6.35        grid_4.4.0           rstudioapi_0.16.0    sandwich_3.1-0      
[37] lifecycle_1.0.4      nlme_3.1-164         vctrs_0.6.5          evaluate_0.23        glue_1.7.0           data.table_1.15.4    numDeriv_2016.8-1.1  zoo_1.8-12           colorspace_2.1-0     fansi_1.0.6          bayestestR_0.13.2    dreamerr_1.4.0
[49] rmarkdown_2.26       tools_4.4.0          htmltools_0.5.8.1 

Thanks for your help!

vincentarelbundock commented 2 months ago

config_modelsummary(factory_default) affects the output format when output="default".

config_modelsummary(factory_latex) affects the output format when output="latex"

This is documented in ?config_modelsummary

chickymonkeys commented 2 months ago

also setting factory_latex to kableExtra with the config function does not restore the behaviour in latex_tabular

vincentarelbundock commented 2 months ago

Right, but following the same logic you can do:

library(modelsummary)
m1 <- lm(mpg ~ hp, mtcars)
options(modelsummary_factory_default = "latex_tabular")
options(modelsummary_factory_latex_tabular = "kableExtra")
modelsummary(m1)
vincentarelbundock commented 2 months ago

oops, right, there's no latex_tabular argument in config_modelsummary(). You can just use the options() then.