Non English (Hebrew) output in RStudio console

扶醉桌前 提交于 2020-01-04 00:40:11

问题


The following test works fine on my laptop, but produces an error on my HP EliteOne 800 running Windows 10

H <- "שלום"

H

In the machine with the problem I get

[1] "ùìåí"

I tested several encoding, such as

Encoding(H)  <- "ISO-8859-1"

which gives the same output, and

Encoding(H)<-"UTF-8"
H

that produces

[1] "\xf9\xec\xe5\xed"

Below is the response to

sessionInfo()

R version 3.2.2 (2015-08-14) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 8 x64 (build 9200)

locale: [1] LC_COLLATE=Hebrew_Israel.1255 LC_CTYPE=Hebrew_Israel.1255 LC_MONETARY=Hebrew_Israel.1255 [4] LC_NUMERIC=C
LC_TIME=Hebrew_Israel.1255

attached base packages: [1] stats graphics grDevices utils
datasets methods base

loaded via a namespace (and not attached): [1] tools_3.2.2

Any help will be appreciated,

Avi


回答1:


Thank you Richard, you led me to a solution that works -- although I do not understand why. I played with various codes, and accidentally changed my locale to Japanese and it works. Than I tested various other locales and they do the same trick. If any one knows why the Hebrew does not work with Hebrew locale, I would like to know. Below is the code and its product:

H <- "שלום"
H
Sys.getlocale()

Sys.setlocale("LC_ALL", "Hebrew")

H <- "שלום"
H
Sys.getlocale()

Sys.setlocale("LC_ALL", "ja")
H <- "שלום"
H

Sys.setlocale("LC_ALL", "Portuguese_Brazil.1252")
H <- "שלום"
H

Sys.setlocale("LC_ALL", "German")
H <- "שלום"
H produces the following output, where only the Hebrew locale does not show Hebrew.

H <- "שלום"

H

> [1] "ùìåí" #THE PROBLEM IN HEBREW

Sys.getlocale()

[1]"LC_COLLATE=Hebrew_Israel.1255;LC_CTYPE=Hebrew_Israel.1255;LC_MONETARY=Hebrew_Israel.1255;LC_NUMERIC=C;LC_TIME=Hebrew_Israel.1255"

Sys.setlocale("LC_ALL", "Hebrew")

[1]"LC_COLLATE=Hebrew_Israel.1255;LC_CTYPE=Hebrew_Israel.1255;LC_MONETARY=Hebrew_Israel.1255;LC_NUMERIC=C;LC_TIME=Hebrew_Israel.1255"

H <- "שלום" H

> [1] "ùìåí" #THE PROBLEM IN HEBREW

Sys.getlocale()

[1]LC_COLLATE=Hebrew_Israel.1255;LC_CTYPE=Hebrew_Israel.1255;LC_MONETARY=Hebrew_Israel.1255;LC_NUMERIC=C;LC_TIME=Hebrew_Israel.1255"

Sys.setlocale("LC_ALL", "ja")

[1]"LC_COLLATE=Japanese_Japan.932;LC_CTYPE=Japanese_Japan.932;LC_MONETARY=Japanese_Japan.932;LC_NUMERIC=C;LC_TIME=Japanese_Japan.932"

> H <- "שלום" #THE SOLUTION IN OTHER LANGUAGE THAT WORKS -- ALSO SEE BELOW

H

[1] "שלום"

Sys.setlocale("LC_ALL", "Portuguese_Brazil.1252") [1]"LC_COLLATE=Portuguese_Brazil.1252;LC_CTYPE=Portuguese_Brazil.1252;LC_MONETARY=Portuguese_Brazil.1252;LC_NUMERIC=C;LC_TIME=Portuguese_Brazil.1252"

H <- "שלום"

H

[1] "שלום"

Sys.setlocale("LC_ALL", "German") [1]"LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252"

H <- "שלום"

H

[1] "שלום"



来源:https://stackoverflow.com/questions/34209851/non-english-hebrew-output-in-rstudio-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!