Yihui Xie
2013-Apr-10 19:34 UTC
[Rd] localeToCharset() returns NA for the Hong Kong locale
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