question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Windows UTF-8 version of R

See original GitHub issue

An experimental build of R using UTF-8 as native encoding on Windows has been released recently, and here is the instruction: https://svn.r-project.org/R-dev-web/trunk/WindowsBuilds/winutf8/ucrt3/howto.html

I’m on Windows 10 20H2 and has set $LANG to zh_CN.UTF-8. After setting the codepage to 65001(UTF-8), the encoding in Rterm successfully switches to UTF-8, but the encoding in radian remains unchanged.

image

In most of the time the terminal and the graph can still handle CJK characters properly. But sometimes some messy codes show, like the red text in the screenshot.

I thought this issue came from Python itself, so I set $PYTHONUTF8 to 1 to force Python to use UTF-8, and ran python -m radian instead of radian. However it doesn’t work for radian. I also tried to directly change the encoding in radian, and then it crashed.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:28 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
Yunuuuucommented, Jun 29, 2022

Only set LANG environment is not sufficient to make this work well, I must set locale manually by adding following code in my .Rprofile.

            # Set locale to utf8
            is_uft8_support <- grepl(
                "UTF-8|utf8", Sys.getenv("LANG"),
                ignore.case = TRUE, perl = TRUE
            ) &&
                R.version$major >= 4L &&
                R.version$minor >= 2.0
            if (is_uft8_support) {
                suppressWarnings(Sys.setlocale("LC_ALL", Sys.getenv("LANG")))
            }

This is my radian version: image

when use raw radian without setting above code in my .Rprofile, the R sessionInfo and l10n_info indicate UTF-8 encoding isn’t work. When we read file with special character using data.table::fread, some characters won’t be parsed correctly image After setting locale, this works fine, and when we read file with special character using data.table::fread, special characters can be parsed successfully. image

1reaction
SpecterShellcommented, Aug 6, 2022

Where is the .Rprofile in vscode? I am new to R, and have little idea as to where to configure it… Thanks in advance!

%USERPROFILE%\Documents\.Rprofile

Read more comments on GitHub >

github_iconTop Results From Across the Web

UTF-8 Support on Windows - The R Blog
UCRT can be installed on older versions of Windows, but UTF-8 support will only work on Windows 10 (November 2019 update) and newer....
Read more >
UTF-8 support in R on Windows - Stack Overflow
It is I think the only realistic way to support Unicode characters (not representable in native encoding) reliably in R on Windows. It...
Read more >
What is the state of UTF-8 support on Windows 10 with R 4.0?
There was an R blog post announcing UTF-8 support on Windows 10, starting with R 4.0. It says: In the experimental build of...
Read more >
Use Unicode UTF-8 for worldwide language support" option in ...
"Beta: Use Unicode UTF-8 for worldwide language support". I can see this option in windows 10 but not in server 2016. windows-serverwindows- ...
Read more >
State of UTF-8 support on Windows? : r/cpp - Reddit
Two years ago, Windows 10 version 1803 started to add support for setting the locale to UTF-8. This enabled the ANSI versions of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found