From xie at yihui.name  Wed Apr 10 21:34:41 2013
From: xie at yihui.name (Yihui Xie)
Date: Wed, 10 Apr 2013 14:34:41 -0500
Subject: [Rd] localeToCharset() returns NA for the Hong Kong locale
Message-ID: <CANROs4eVUctLb1ZUEhAbrbKjtzD1Mgk5U6C_DwBNXO7ohw-fRw@mail.gmail.com>

Hi,

When Sys.getlocale("LC_CTYPE") returns 'Chinese (Traditional)_Hong
Kong S.A.R..950' to some Hong Kong Windows users, localeToCharset()
returns NA instead of CP950 due to:

> localeToCharset
....
    if (.Platform$OS.type == "windows") {
        x <- strsplit(locale, ".", fixed = TRUE)[[1L]]
        if (length(x) != 2)
            return(NA_character_)
        switch(x[2L], `1252` = return("ISO8859-1"), `1257` =
return("ISO8859-13"))
        return(paste0("CP", x[2L]))
    }
....

Perhaps you should not assume length(x) == 2 when the locale string is
split by ., since in this case the dots in S.A.R. have a different
meaning (abbrev for Special Administrative Region). I would suggest
check if length(x) >= 2 and use the last element of x. Maybe you have
good reasons to require length(x) == 2.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



[Rd] localeToCharset() returns NA for the Hong Kong locale
Yihui Xie