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

Inconsistency in text_replace with underscores in html and latex #1592

Open
6 tasks done
AaronGullickson opened this issue Feb 26, 2024 · 0 comments
Open
6 tasks done
Assignees

Comments

@AaronGullickson
Copy link
Contributor

Prework

Description

If you want to replace text that includes an underscore (e.g. "test_x") using text_replace or text_transform, the required pattern is different for HTML output and LaTeX output. For HTML output, you can use the underscore directly, while for latex you must double escape it (e.g. test\\\\_x). See the reproducible example below which will produce different results when rendered to HTML rather than PDF.

I experimented with several other special characters (*, :, -, and .). All of these characters worked fine in both formats without double-escaping, so this appears to be a specific problem with underscores.

Reproducible example

  • Post a minimal reproducible example so the maintainer can troubleshoot the problems you identify. A reproducible example is:
    • Runnable: post enough R code and data so any onlooker can create the error on their own computer.
    • Minimal: reduce runtime wherever possible and remove complicated details that are irrelevant to the issue at hand.
    • Readable: format your code according to the tidyverse style guide.
---
title: "Test"
format:
  html: default
  pdf:
    keep-tex: true
---

```{r}
#| include: false

library(gt)
library(tidyverse)
```

```{r}
tbl <- tibble(
  names = c("test_x", "test_y", "test_z"),
  col1 = 1:3,
  col2 = 4:6
)

tbl |>
  gt() |>
  text_replace(pattern = "test_x", replacement = "Worked!")

tbl |>
  gt() |>
  text_replace(pattern = "test\\\\_y", replacement = "Worked!")

```

```{r}
sessionInfo()
```

Expected result

The result should be the same in HTML and PDF. Preferably, you would be able to run the pattern without double-escaping.

Session info

End the reproducible example with a call to sessionInfo() in the same session (e.g. reprex(session_info = TRUE)) and include the output.

R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.3.1

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Los_Angeles
tzcode source: internal

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

other attached packages:
 [1] lubridate_1.9.3 forcats_1.0.0   stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2     readr_2.1.5    
 [7] tidyr_1.3.1     tibble_3.2.1    ggplot2_3.4.4   tidyverse_2.0.0 gt_0.10.1.9000 

loaded via a namespace (and not attached):
 [1] gtable_0.3.4      xfun_0.42         htmlwidgets_1.6.4 devtools_2.4.5    remotes_2.4.2.1  
 [6] processx_3.8.3    callr_3.7.3       tzdb_0.4.0        ps_1.7.6          vctrs_0.6.5      
[11] tools_4.3.2       generics_0.1.3    curl_5.2.0        fansi_1.0.6       pkgconfig_2.0.3  
[16] desc_1.4.3        lifecycle_1.0.4   compiler_4.3.2    munsell_0.5.0     httpuv_1.6.14    
[21] htmltools_0.5.7   usethis_2.2.2     sass_0.4.8        pillar_1.9.0      later_1.3.2      
[26] urlchecker_1.0.1  ellipsis_0.3.2    cachem_1.0.8      sessioninfo_1.2.2 mime_0.12        
[31] commonmark_1.9.1  tidyselect_1.2.0  digest_0.6.34     stringi_1.8.3     fastmap_1.1.1    
[36] grid_4.3.2        colorspace_2.1-0  cli_3.6.2         magrittr_2.0.3    pkgbuild_1.4.3   
[41] utf8_1.2.4        withr_3.0.0       scales_1.3.0      promises_1.2.1    timechange_0.3.0 
[46] hms_1.1.3         memoise_2.0.1     shiny_1.8.0       knitr_1.45        miniUI_0.1.1.1   
[51] markdown_1.12     profvis_0.3.8     rlang_1.1.3       Rcpp_1.0.12       xtable_1.8-4     
[56] glue_1.7.0        xml2_1.3.6        pkgload_1.3.4     rstudioapi_0.15.0 R6_2.5.1         
[61] fs_1.6.3 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants