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

Error in grep(pattern, bfr, value = TRUE), unable to translate to a wide string #52

Closed
olivroy opened this issue Feb 26, 2024 · 2 comments

Comments

@olivroy
Copy link

olivroy commented Feb 26, 2024

I see this problem when I use the styler addin ever since I upgraded to R 4.3.0. I tried to narrow it down, and I think R.cache may be the culprit.

Can't reproduce with a reprex, but here is what I see in interactive session.

My OS is Windows and R is in a French locale.

options(warn = 2) 
R.cache::getCachePath("styler")
Erreur dans grep(pattern, bfr, value = TRUE) :    
(converti depuis l'avis) unable to translate ' Le num<82>ro de s<82>rie du volume est 1451-5EA6' to a wide string 

 traceback()
18: doWithOneRestart(return(expr), restart)
17: withOneRestart(expr, restarts[[1L]])
16: withRestarts({         .Internal(.signalCondition(simpleWarning(msg, call), msg,              call))         .Internal(.dfltWarn(msg, call))     }, muffleWarning = function() NULL)
15: .signalSimpleWarning("unable to translate ' Le num<82>ro de s<82>rie du volume est 1451-5EA6' to a wide string",          base::quote(grep(pattern, bfr, value = TRUE)))
14: grep(pattern, bfr, value = TRUE)
13: FUN(X[[i]], ...)
12: lapply(X = X, FUN = FUN, ...)
11: sapply(paths, FUN = readlink, USE.NAMES = FALSE)
10: Sys.readlink2(pathname, what = "corrected")
9: fileAccess.default(pathT, mode = 2)
8: fileAccess(pathT, mode = 2)
7: getWritablePathname.Arguments(static, file = "dummy-not-created",         path = path, ...)
6: getWritablePathname(static, file = "dummy-not-created", path = path,         ...)
5: getWritablePath.Arguments(static, ...)
4: getWritablePath(static, ...) at <text>#1
3: Arguments$getWritablePath(path)
2: getCachePath.default("styler")
1: R.cache::getCachePath("styler")
R.cache::getCachePath("styler")
#> [1] "C:\\Users\\user\AppData\\Local\\R\\cache\\R\\R.cache/styler"

Created on 2024-02-26 with reprex v2.1.0

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.3.2 (2023-10-31 ucrt)
#>  os       Windows 10 x64 (build 19044)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  French_Canada.utf8
#>  ctype    French_Canada.utf8
#>  tz       America/Toronto
#>  date     2024-02-26
#>  pandoc   3.1.11 @ C:/Users/User/AppData/Local/Programs/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version     date (UTC) lib source
#>  cli           3.6.2       2023-12-11 [1] CRAN (R 4.3.2)
#>  digest        0.6.34      2024-01-11 [1] CRAN (R 4.3.1)
#>  evaluate      0.23        2023-11-01 [1] CRAN (R 4.3.2)
#>  fastmap       1.1.1       2023-02-24 [1] CRAN (R 4.3.0)
#>  fs            1.6.3       2023-07-20 [1] CRAN (R 4.3.1)
#>  glue          1.7.0       2024-01-09 [1] CRAN (R 4.3.2)
#>  htmltools     0.5.7       2023-11-03 [1] CRAN (R 4.3.2)
#>  knitr         1.45        2023-10-30 [1] CRAN (R 4.3.1)
#>  lifecycle     1.0.4       2024-02-14 [1] Github (r-lib/lifecycle@9302cea)
#>  magrittr      2.0.3       2022-03-30 [1] CRAN (R 4.3.0)
#>  purrr         1.0.2       2023-08-10 [1] CRAN (R 4.3.1)
#>  R.cache       0.16.0      2022-07-21 [1] CRAN (R 4.3.1)
#>  R.methodsS3   1.8.2       2022-06-13 [1] CRAN (R 4.3.0)
#>  R.oo          1.26.0      2024-01-24 [1] CRAN (R 4.3.2)
#>  R.utils       2.12.3      2023-11-18 [1] CRAN (R 4.3.2)
#>  reprex        2.1.0       2024-01-11 [1] CRAN (R 4.3.2)
#>  rlang         1.1.3.9000  2024-02-21 [1] Github (r-lib/rlang@009f8e3)
#>  rmarkdown     2.25        2023-09-18 [1] CRAN (R 4.3.1)
#>  rstudioapi    0.15.0.9000 2024-02-22 [1] Github (rstudio/rstudioapi@5b639f9)
#>  sessioninfo   1.2.2       2021-12-06 [1] CRAN (R 4.3.0)
#>  styler        1.10.2      2023-08-29 [1] CRAN (R 4.3.1)
#>  vctrs         0.6.5       2023-12-01 [1] CRAN (R 4.3.2)
#>  withr         3.0.0       2024-01-16 [1] CRAN (R 4.3.1)
#>  xfun          0.42        2024-02-08 [1] CRAN (R 4.3.2)
#>  yaml          2.3.8       2023-12-11 [1] CRAN (R 4.3.2)
#> 
#>  [1] C:/Users/user/AppData/Local/R/win-library/4.3
#>  [2] C:/Program Files/R/R-4.3.2/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

 I also get a couple extra warnings when trying to style a file, all seemignly coming from the same place,

Messages d'avis :
1: Dans grep(pattern, bfr, value = TRUE) :
  unable to translate ' Le num<82>ro de s<82>rie du volume est 1451-5EA6' to a wide string
2: Dans grep(pattern, bfr, value = TRUE) : input string 2 is invalid
3: Dans grep(pattern, bfr, value = TRUE) :
  unable to translate ' R<82>pertoire de C:\Users\RoyO\AppData\Local\R\cache\R\R.cache' to a wide string
4: Dans grep(pattern, bfr, value = TRUE) : input string 4 is invalid
5: Dans grep(pattern, bfr, value = TRUE) :
  unable to translate '               3 R<82>p(s)  46<ff>600<ff>630<ff>272 octets libres' to a wide string
6: Dans grep(pattern, bfr, value = TRUE) : input string 11 is invalid

It may be due to the fact that regexps are stricter in R 4,3,0
From the changelog:
Regular expression functions now check more thoroughly whether their inputs are valid strings (in their encoding, e.g. in UTF-8).

The performance of grep(), sub(), gsub() and strsplit() has been improved, particularly with perl = TRUE and fixed = TRUE. Use of useBytes = TRUE for performance reasons should no longer be needed and is discouraged: it may lead to incorrect results.

@olivroy
Copy link
Author

olivroy commented Feb 26, 2024

Oh, actually the culprit code may be in R.utils

https://github.com/HenrikBengtsson/R.utils/blob/0382c2e4628f53e5ca9ef821484e28443b87cc2f/R/Sys.readlink2.R#L56

@olivroy
Copy link
Author

olivroy commented Feb 27, 2024

Actually an issue in R.utils. See HenrikBengtsson/R.utils#152

@olivroy olivroy closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
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

Successfully merging a pull request may close this issue.

1 participant