haozhu233 / kableExtra

Construct Complex Table with knitr::kable() + pipe.
https://haozhu233.github.io/kableExtra/
Other
688 stars 147 forks source link

Error in gsub("\\\\", "\\\\\\\\", x) #754

Closed aipe closed 10 months ago

aipe commented 1 year ago

When runing the code on the RStudio R console, we get the following error message:

Error in gsub("\\", "\\\\", x) : input string 1 is invalid

Code:

library(kableExtra)
options(knitr.kable.NA = "-")

structure(list(transport.mode = structure(c(1L, 3L), levels = c("vélo", "voiture", "pied", "train", "bus", "tram"), class = "factor"),
    mean_all = c("1.79 $[1.68-1.89]$", NA), n_all = c(1136L,
    60L), mean_peak = c("2.08 $[1.95-2.2]$", NA), n_peak = c(797L,
    NA), mean_off = c("1.12 $[0.99-1.26]$", NA), n_off = c(339L,
    60L)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", "data.frame"))

kable(data, format = "latex", escape = FALSE, row.names = FALSE, col.names = c('Transport', 'BC [µg/m³]', 'n', 'BC [µg/m³]', 'n', 'BC [µg/m³]', 'n'), booktabs = TRUE, align = 'c', digits = 2, caption = "Concentrations moyennes de BC issues de vos données individuelles en RB-C") %>%
  row_spec(0, bold = T) %>%
  add_header_above(c(" " = 1, "Données complètes" = 2, "Données en heures de pointe" = 2, "Données en heures creuses" = 2), bold = TRUE)

Any of the last two lines leads to the error with the same message.

The sessionInfo():

R version 4.3.0 (2023-04-21 ucrt)

Platform: x86_64-w64-mingw32/x64 (64-bit)

Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:

[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 LC_NUMERIC=C LC_TIME=French_France.1252

system code page: 65001

time zone: Europe/Brussels

tzcode source: internal

attached base packages:

[1] stats graphics grDevices utils datasets methods base

other attached packages:

[1] kableExtra_1.3.4 scales_1.2.1 rlang_1.1.1 ggplot2_3.4.2 gplots_3.1.3 sf_1.0-12 plotKML_0.8-3 tibble_3.2.1 stringi_1.7.12 openair_2.17-0 readr_2.1.4 readxl_1.4.2 xlsx_0.6.5

[14] lubridate_1.9.2 dplyr_1.1.2 pacman_0.5.1

loaded via a namespace (and not attached):

[1] DBI_1.1.3 bitops_1.0-7 aqp_1.42 deldir_1.0-6 magrittr_2.0.3 e1071_1.7-13 compiler_4.3.0 mgcv_1.8-42 systemfonts_1.0.4 png_0.1-8 vctrs_0.6.2

[12] maps_3.4.1 rvest_1.0.3 stringr_1.5.0 pkgconfig_2.0.3 fastmap_1.1.1 lwgeom_0.2-11 caTools_1.18.2 utf8_1.2.3 rmarkdown_2.21 tzdb_0.3.0 purrr_1.0.1

[23] xfun_0.39 xlsxjars_0.6.1 jpeg_0.1-10 terra_1.7-29 parallel_4.3.0 cluster_2.1.4 R6_2.5.1 RColorBrewer_1.1-3 cellranger_1.1.0 stars_0.6-1 Rcpp_1.0.10

[34] bookdown_0.34 knitr_1.42 zoo_1.8-12 FNN_1.1.3.2 Matrix_1.5-4 splines_4.3.0 timechange_0.2.0 tidyselect_1.2.0 rstudioapi_0.14 abind_1.4-5 yaml_2.3.7

[45] codetools_0.2-19 lattice_0.21-8 intervals_0.15.3 plyr_1.8.8 withr_2.5.0 evaluate_0.21 rJava_1.0-6 units_0.8-2 proxy_0.4-27 xts_0.13.1 xml2_1.3.4

[56] pillar_1.9.0 KernSmooth_2.23-20 generics_0.1.3 colorRamps_2.3.1 sp_1.6-0 spacetime_1.3-0 hms_1.1.3 munsell_0.5.0 rgdal_1.6-6 pixmap_0.4-12 gtools_3.9.4

[67] class_7.3-21 glue_1.6.2 mapproj_1.2.11 tools_4.3.0 interp_1.1-4 hexbin_1.28.3 data.table_1.14.8 webshot_0.5.4 XML_3.99-0.14 grid_4.3.0 tidyr_1.3.0

[78] latticeExtra_0.6-30 colorspace_2.1-0 nlme_3.1-162 raster_3.6-20 cli_3.6.1 gstat_2.1-1 fansi_1.0.4 viridisLite_0.4.2 svglite_2.1.1 gtable_0.3.3 digest_0.6.31

[89] classInt_0.4-9 farver_2.1.1 htmltools_0.5.5 lifecycle_1.0.3 dismo_1.3-9 httr_1.4.6 MASS_7.3-58.4

aipe commented 1 year ago

Closing since this issue was due to non-UTF8 locale