Sunday, March 25, 2018

r - How to display a message/warning/error with Unicode characters under Windows?

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"


Under Linux, this prints OK in a message if the locale is UTF-8 (l10n_info()$`UTF-8` returns TRUE).



I can force this, by doing, e.g.,



devtools::with_locale(
c(LC_CTYPE = "en_US.utf8"),
message(x)
)
## € 네


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)
)
## €


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")


How can I get UTF-8 messages, warnings and errors to display correctly under Windows?

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...