rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
2.03k stars 209 forks source link

Characters generated using `fmt_number()` with the `pattern` argument are not escaped when rendered with `as_latex()` #842

Open JohannesNE opened 3 years ago

JohannesNE commented 3 years ago

If I try to add a % after a number, with fmt_number(pattern = "{x} %"), the % is not escaped when the table is converted to latex. (I know I should use fmt_percent() but my actual pattern is a bit more complicated).

library(gt)

test_table <- gt(exibble[1:2,1:2]) %>% 
  fmt_number(columns = "num", rows = 1, pattern = "{x} %")

test_table

image

test_table %>% 
  as_latex() %>% 
  as.character() %>% 
  cat()
#> \captionsetup[table]{labelformat=empty,skip=1pt}
#> \begin{longtable}{rl}
#> \toprule
#> num & char \\ 
#> \midrule
#> $0.11$ % & apricot \\ 
#> 2.222 & banana \\ 
#>  \bottomrule
#> \end{longtable}

Created on 2021-10-27 by the reprex package (v2.0.0)

rich-iannone commented 2 years ago

Thanks for filing this issue. This is a pretty bad bug so I’m hoping to get a fix for it sooner than later!