Closed cicdguy closed 5 months ago
Thanks for the good repro. If I am not mistaken, utils::getParseData()
is the problem here and styler has nothing to do with it? @IndrajeetPatil maybe you can jump in.
Yes indeed. This is likely an R-related issue as seen previously as well.
Seeking advice here - is there some way styler can somehow ignore Unicode characters?
I can check this tomorrow on my Ubuntu machine, but it is a bit strange that, if indeed there has been this regression in R >= 4.4
, the encoding test doesn't fail either on release or devel version: https://github.com/r-lib/styler/pull/1200.
I can't reproduce this locally on Ubuntu either.
Here is a reprex with session info:
utils::getParseData(parse(text = 'suit <- "♠"'))
#> line1 col1 line2 col2 id parent token terminal text
#> 7 1 1 1 11 7 0 expr FALSE
#> 1 1 1 1 4 1 3 SYMBOL TRUE suit
#> 3 1 1 1 4 3 7 expr FALSE
#> 2 1 6 1 7 2 7 LEFT_ASSIGN TRUE <-
#> 4 1 9 1 11 4 6 STR_CONST TRUE "♠"
#> 6 1 9 1 11 6 7 expr FALSE
Created on 2024-05-06 with reprex v2.1.0
@cicdguy Can you please post a reprex with session info so we can check what's different between our/GitHub and your machines?
Hmm, I can reproduce the output you are seeing in the container:
# echo 'a <- "R² μ ≥"' > ex.R
# R -s -e 'styler::style_file("ex.R")'
Styling 1 files:
ex.R i
----------------------------------------
Status Count Legend
v 0 File unchanged.
i 1 File changed.
x 0 Styling threw an error.
----------------------------------------
Please review the changes carefully!
# cat ex.R
a <- "R<U+00B2> <U+03BC> <U+2265>"
Can this be an issue in Rocker's image? Can anyone reproduce this without using this image?
@eitsupi Maybe you have some idea as to what might be going on here?
Perhaps it is a locale issue? See rocker-org/rocker-versioned2#802.
Try setting the environment variable LANG=en_US.UTF-8
.
It is indeed a locale issue. Setting LANG=en_US.UTF-8
works like a charm. I guess I'll just set this on the containers going forward.
Thank you all! 🙏🏽
Sorry for bothering you. I have triggered a new build, so will fix this.
Thanks for the quick reply and fix, @eitsupi. You Rock(er)! 🤘
Ok, but it’s still a problem in base r and setting the locale is more of a workaround, no?
Ok, but it’s still a problem in base r and setting the locale is more of a workaround, no?
No, it was an issue with the Rocker image of base-R, not in the base-R itself. This is why the issue was reproducible neither locally nor on GitHub, but only in Docker containers using the said image. But the image has already been fixed, so this is no longer an issue.
So parsing a <- "R² μ ≥"
is expected to give something meaningful only if LANG is set?
Hello,
I believe we are seeing a regression of https://github.com/r-lib/styler/issues/847 in R 4.4.0 on Linux. MacOS does not have this issue, and I haven't tested it on Windows.
Steps to reproduce
Start a shell using the rocker/verse:4.4.0 image
Observe the OS version
Install styler from CRAN
Create a simple file containing unicode characters
Style the file
Observe the re-styled file
Supplemental Information
Running
utils::getParseData(parse(text = 'suit <- "♠"'))
in the container gives me:But running on my MacOS laptop gives me: