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"
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"
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?
`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?
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: