Post

1 follower Follow
0
Avatar

sort order

Hi, RStudio team,

Now this is odd...
In R.app or R command line:

sort(c("a","A","b","B"))
[1] "a" "A" "b" "B"
But in RStudio
sort(c("a","A","b","B"))
[1] "A" "B" "a" "b"

I've verified all 3 are running R.2.14.0, starting in the user home, running the same .Rprofile.

Ian Pylvainen

5 comments

0
Avatar

Or, trying to correct the odd message formatting:

Hi, RStudio team,

Now this is odd...
In R.app or R command line:

sort(c("a","A","b","B")) [1] "a" "A" "b" "B"

But in RStudio
sort(c("a","A","b","B")) [1] "A" "B" "a" "b"

I've verified all 3 are running R.2.14.0, starting in the user home, running the same .Rprofile.

Ian Pylvainen 0 votes
0
Avatar

Text sorting rules are affected by your locale settings, specifically LC_COLLATE.

It looks as though RStudio (at least on the Mac) uses the "C" collation setting which turns off locate-specific sorting.

> Sys.getlocale("LC_CTYPE")
[1] "en_US.UTF-8"
> Sys.getlocale("LC_COLLATE")
[1] "C"
> sort(c("a","A","b","B"))
[1] "A" "B" "a" "b"

It can by set with the Sys.setlocale() function:

> Sys.setlocale("LC_COLLATE", "en_US.UTF-8")
[1] "en_US.UTF-8"
> sort(c("a","A","b","B"))
[1] "a" "A" "b" "B"

The RGui (again, at least on the Mac), sets the collation to match the locale:

> Sys.getlocale("LC_CTYPE")
[1] "en_US.UTF-8"
> Sys.getlocale("LC_COLLATE")
[1] "en_US.UTF-8"
> sort(c("a","A","b","B"))
[1] "a" "A" "b" "B"

If it matters for your application, it's probably safest to set the collation explicitly, but it would be nice if RStudio adopted RGui's convention.

HTH,
Jeffrey

Ian Pylvainen 0 votes
0
Avatar

Thanks for reporting and thanks Jeffrey for clarifying the behavior. I've filed a bug for us to look into making this consistent.

Josh

Ian Pylvainen 0 votes
0
Avatar

Fascinating!!

Thanks a lot for your reply.
Could be very important, especially to devotees of reproducible research.

Roger Day
University of Pittsburgh Departments of Biomedical Informatics and

Biostatistics

University of Pittsburgh Cancer Institute

Room 310, Suite 301
Cancer Pavilion (CNPAV)
5150 Centre Ave.
Pittsburgh, PA 15232
e-mail: day01@pitt.edu
cell phone 412-609-3918
assistant:

Nova Smith: (412) 623-8382

Ian Pylvainen 0 votes
0
Avatar

Hey all,

Wanted to let you know that this issue should be fixed now and it will be available in the next version of RStudio (v0.97). If you've like to test it out now, you can try out the latest preview:

http://www.rstudio.org/download/preview

We'd love for you to confirm that it's all good here.

Josh

Ian Pylvainen 0 votes