Love the modelsummary
package, but since updating to the latest version, I can't even get the simplest possible regression table to compile without errors in Overleaf.
Consider the following R code:
library("groundhog") # for temporal reproducibility
meta.groundhog(date = "2024-04-30")
groundhog.library("modelsummary", date = "2024-04-30")
set.seed(05232024) # for result reproducibility
x <- rnorm(100)
y <- x*2 + rnorm(100)
fit <- lm(y ~ x)
modelsummary(fit, output = "latex")
which produces the following LaTeX code:
\begin{table}
\centering
\begin{tblr}[ %% tabularray outer open
] %% tabularray outer close
{ %% tabularray inner open
colspec={Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=c,},
hline{6}={1,2}{solid, 0.05em, black},
} %% tabularray inner close
\toprule
& (1) \\ \midrule %% TinyTableHeader
(Intercept) & 0.010 \\
& (0.093) \\
x & 1.868 \\
& (0.086) \\
Num.Obs. & 100 \\
R2 & 0.827 \\
R2 Adj. & 0.825 \\
AIC & 272.5 \\
BIC & 280.3 \\
Log.Lik. & -133.254 \\
F & 468.067 \\
RMSE & 0.92 \\
\bottomrule
\end{tblr}
\end{table}
If I put this into a text editor with a TeX installation (or Overleaf, I've tried in several different ways), I always get errors. I use \usepackage{tabularray}
and \usepackage{booktabs}
. By my reading, it's not clear that I need other packages but perhaps I'm missing something? I've tried to update my TeX installation, used Overleaf, etc.
Overleaf error message:
<argument> \color
{\l__tblr_f_tl }
l.42 \end
{tblr}
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
Am I missing something? Is it possible to return to the old modelsummary
output?
The only other thing I can think of is that modelsummary
returns this message when loading:
`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')
but I don't think this is the issue because I've tried to revert to kableExtra
with the same results.
If you knit to a pdf you might observe the following included:
## Warning: To compile a LaTeX document with this table, the following commands must be placed in the document preamble:
##
## \usepackage{tabularray}
## \usepackage{float}
## \usepackage{graphicx}
## \usepackage{codehigh}
## \usepackage[normalem]{ulem}
## \UseTblrLibrary{booktabs}
## \UseTblrLibrary{siunitx}
## \newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
## \newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
## \NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
##
## To disable `siunitx` and prevent `modelsummary` from wrapping numeric entries in `\num{}`, call:
##
## options("modelsummary_format_numeric_latex" = "plain")
## This warning appears once per session.
Therefore, your Overleaf could look something like this:
\documentclass{article}
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage{codehigh}
\usepackage[normalem]{ulem}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{siunitx}
\newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
\newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
\NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
\begin{document}
\begin{table}
\centering
\begin{tblr}[ %% tabularray outer open
] %% tabularray outer close
{ %% tabularray inner open
colspec={Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=c,},
hline{6}={1,2}{solid, 0.05em, black},
} %% tabularray inner close
\toprule
& (1) \\ \midrule %% TinyTableHeader
(Intercept) & 0.010 \\
& (0.093) \\
x & 1.868 \\
& (0.086) \\
Num.Obs. & 100 \\
R2 & 0.827 \\
R2 Adj. & 0.825 \\
AIC & 272.5 \\
BIC & 280.3 \\
Log.Lik. & -133.254 \\
F & 468.067 \\
RMSE & 0.92 \\
\bottomrule
\end{tblr}
\end{table}
\end{document}