Sunday, 30 October 2016

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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...