[Rd] localeToCharset() returns NA for the Hong Kong locale
Yihui Xie
xie at yihui.name
Wed Apr 10 21:34:41 CEST 2013
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
More information about the R-devel
mailing list