Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

escape=FALSE ignored for output="latex_tabular/latex" #740

Closed
adamaltmejd opened this issue Apr 4, 2024 · 3 comments
Closed

escape=FALSE ignored for output="latex_tabular/latex" #740

adamaltmejd opened this issue Apr 4, 2024 · 3 comments

Comments

@adamaltmejd
Copy link

Hey! Thanks for a great package! Although I'm loving tinytable, for my old code I'm now trying fix all the stuff that 2.0 broke for me :). I'm using latex_tabular with siunitx (first row is \begin{tabular}[S[table-format=....] so had to use lots of regex to change it back), but I think I also found a bug with escape=FALSE still escaping backslashes and curly braces. Using latest Github version of modelsummary.

library(modelsummary)
library(data.table)
tbl <- data.table("a"=c(1,2,3), "{}" = c(4,"\\times 5",6))
> datasummary_df(tbl, output = "latex_tabular", escape = TRUE)
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=l,},
}                     %% tabularray inner close
\toprule
a & \{\} \\ \midrule %% TinyTableHeader
\num{1.00} & 4                        \\
\num{2.00} & \textbackslash{}times 5 \\
\num{3.00} & 6                        \\
\bottomrule
\end{tblr} 
> datasummary_df(tbl, output = "latex_tabular", escape = FALSE)
\begin{tblr}[         %% tabularray outer open
]                     %% tabularray outer close
{                     %% tabularray inner open
colspec={Q[]Q[]},
column{1}={halign=l,},
column{2}={halign=l,},
}                     %% tabularray inner close
\toprule
a & \{\} \\ \midrule %% TinyTableHeader
\num{1.00} & 4                        \\
\num{2.00} & \textbackslash{}times 5 \\
\num{3.00} & 6                        \\
\bottomrule
\end{tblr} 
@adamaltmejd adamaltmejd changed the title escape not working escape=FALSE ignored for output="latex_tabular/latex" Apr 4, 2024
@adamaltmejd
Copy link
Author

And a quick follow-up; how do I ensure output is using kableExtra when output="latex_tabular". Setting options("modelsummary_factory_default" = "kableExtra") does not matter.

vincentarelbundock added a commit that referenced this issue Apr 4, 2024
@vincentarelbundock
Copy link
Owner

Aww, sorry to hear that! I was really hoping that options() and config_modelsummary() would be sufficient for most people.

Yep, you found a bug in datasummary_df(). Should be fixed on Github now.

For that, I would do:

library(modelsummary)
library(data.table)
tbl <- data.table("a"=c(1,2,3), "{}" = c(4,"\\times 5",6))

options(modelsummary_factory_default = "latex_tabular")
options(modelsummary_factory_latex_tabular = "kableExtra")

datasummary_df(tbl)

@adamaltmejd
Copy link
Author

adamaltmejd commented Apr 5, 2024

Hehe completely got myself to blame for doing too much messy customization :). Nothing a bit of regexp can't solve though :).

Thanks! Had missed "modelsummary_factory_latex_tabular".

A small and not very important request for the future: Since I run all my code using targets pipelines, everything is called from within functions in separate R sessions, code becomes much easier to interpret when options can be set directly in the function call rather than with options(). An optional argument that defaults to options(modelsummary_factory_latex_tabular = "kableExtra") would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants