Search code examples
rrstudio

RStudio does not read non-English characters in paths


I want to list files and folders containing Japanese characters in my working directory with list.files(), but when I tried this, it does not show the proper files names.

For example, the "test" direcotry has folders "test1", "test2", "テスト3", and running list.files() gives unreadable characters for the one with Japanese characters like this.

> getwd()
[1] "C:/Users/10040153/Documents/test"
> list.files()
[1] "繝<86>繧ケ繝<88>3" "test1" "test2"

What I tried

  • Set "Default text encoding" to UTR-8
  • Changed locale setting to Japanese with sys.setlocale(locale = "Japanese"), which returned [1]"LC_COLLATE=Japanese_Japan.932;LC_CTYPE=Japanese_Japan.932;LC_MONETARY=Japanese_Japan.932;LC_NUMERIC=C;LC_TIME=Japanese_Japan.932"
  • Reinstalled R and RStudio
  • Rebooted the computer

None of these didn' help.

I doubt this is an issue with RStudio, not R program, because I see no problems with running the same code above in R. Does anybody have an idea?

System environment

  • Windows 10 x64
  • RStudio
  • R version 4.1.2 (2021-11-01)

Update

`Encoding<-`(list.files(), "UTF-8") solved the problem.

> `Encoding<-`(list.files(), "UTF-8")
[1] "テスト3" "test1"   "test2"

I know this has something do with encoding, but how can I make it work in global environemt?


Solution

  • This is a known bug in RStudio; see https://github.com/rstudio/rstudio/issues/10451. If you're willing to try a fix, we have one in the dailies as of last week:

    https://dailies.rstudio.com/