如何在Windows下显示带有Unicode字符的消息/警告/错误? [英] How to display a message/warning/error with Unicode characters under Windows?
问题描述
我有一条包含Unicode字符的消息(或警告或错误). (字符串具有UTF-8
编码.)
I have a message (or warning or error) containing Unicode characters. (The string has UTF-8
encoding.)
x <- "\u20AC \ub124" # a euro symbol, and Hangul 'ne'
## [1] "€ 네"
Encoding(x)
## [1] "UTF-8"
在Linux下,如果语言环境为UTF-8(l10n_info()$`UTF-8`
返回TRUE
),则会在消息中显示OK.
Under Linux, this prints OK in a message if the locale is UTF-8 (l10n_info()$`UTF-8`
returns TRUE
).
我可以通过例如
devtools::with_locale(
c(LC_CTYPE = "en_US.utf8"),
message(x)
)
## € 네
在Windows下,没有UTF-8语言环境,因此我找不到强制执行正确打印的等效方法.例如,在美国语言环境中,韩文字符无法正确显示.
Under Windows there are no UTF-8 locales, so I can't find an equivalent way to enforce correct printing. For example, with a US locale, the Hangul character doesn't display properly.
devtools::with_locale(
c(LC_CTYPE = "English_United States"),
message(x)
)
## € <U+B124>
存在一个相关问题,在Windows下打印数据帧时Unicode字符无法正确显示.那里的建议是将语言环境设置为中文/日文/韩文.这在这里不起作用.
There's a related problem with Unicode characters not displaying properly when printing data frames under Windows. The advice there was to set the locale to Chinese/Japanese/Korean. This does not work here.
devtools::with_locale(
c(LC_CTYPE = "Korean_Korea"),
message(x)
)
## ¢æ ³× # equivalent to iconv(x, "UTF-8", "EUC-KR")
如何获取UTF-8消息,警告和错误以在Windows下正确显示?
How can I get UTF-8 messages, warnings and errors to display correctly under Windows?
推荐答案
我注意到R中的Sys.setlocale()函数的帮助说:"LC_MESSAGES"在不支持消息的系统上为"C"翻译,,并且Windows上不支持.
I noticed that the help for the function Sys.setlocale() in R says this: "LC_MESSAGES" will be "C" on systems that do not support message translation, and is not supported on Windows.
对我来说,这听起来像在任何Windows版本上都无法修改R消息/错误的字符表示形式...
To me this sounds like modifying character representation for R messages/errors can't be done on any Windows version...
这篇关于如何在Windows下显示带有Unicode字符的消息/警告/错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!