You need to change the locale where R is running. Either do this for your entire Windows installation (which seems suboptimal), or within R sessions using:
Sys.setlocale("LC_COLLATE", "C")
Instead of "C" you can use any other valid locale string, but this should return you to the sort order for the letters you want.
Read more ?locales .
I think it's worth noting the sister function Sys.getlocale() , which requests the current setting of the locale parameter. Therefore, you could do
(locCol <- Sys.getlocale("LC_COLLATE")) Sys.setlocale("LC_COLLATE", "lt_LT") sort(letters) Sys.setlocale("LC_COLLATE", locCol) sort(letters) Sys.getlocale("LC_COLLATE") ## giving: > (locCol <- Sys.getlocale("LC_COLLATE")) [1] "en_GB.UTF-8" > Sys.setlocale("LC_COLLATE", "lt_LT") [1] "lt_LT" > sort(letters) [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "y" "j" "k" "l" "m" "n" [16] "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "z" > Sys.setlocale("LC_COLLATE", locCol) [1] "en_GB.UTF-8" > sort(letters) [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" [16] "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" > Sys.getlocale("LC_COLLATE") [1] "en_GB.UTF-8"
which, of course, is what @Hadley Answer shows with_collate() , making it a bit more concise once you have installed devtools .
Gavin Simpson Jan 22 '13 at 12:21 2013-01-22 12:21
source share