Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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"

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)  
)
## € <U+B124>

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?

like image 707
Richie Cotton Avatar asked Sep 21 '15 13:09

Richie Cotton


People also ask

How do I enable Unicode in Windows?

In Microsoft Windows Hexadecimal Unicode input can be enabled by adding a string type (REG_SZ) value called EnableHexNumpad to the registry key HKEY_CURRENT_USER\Control Panel\Input Method and assigning the value data 1 to it.

How do I display Unicode?

Inserting Unicode characters To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X.

Why do some Unicode characters not show up?

If you are unable to read some Unicode characters in your browser, it may be because your system is not properly configured. Here are some basic instructions for doing that. There are two basic steps: Install fonts that cover the characters you need.

How do I show Unicode in HTML?

You can enter any Unicode character in an HTML file by taking its decimal numeric character reference and adding an ampersand and a hash at the front and a semi-colon at the end, for example &#8212; should display as an em dash (—). This is the method used in the Unicode test pages.


1 Answers

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.

To me this sounds like modifying character representation for R messages/errors can't be done on any Windows version...

like image 132
Thomas Avatar answered Oct 18 '22 23:10

Thomas