[R-SIG-Mac] Bug related to locale changes.

Duncan Murdoch murdoch.duncan at gmail.com
Mon Jun 8 15:17:31 CEST 2015


On 08/06/2015 8:37 AM, Berend Hasselman wrote:
> 
>> On 08-06-2015, at 13:40, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>>
>> I posted this to R-devel yesterday; from responses received, it appears
>> to be OSX-specific (maybe Mavericks-specific).
>>
>> In an R session started from the terminal with R --vanilla, I see this:
>>
>>> Sys.setlocale(locale="en_CA")
>> [1] "en_CA/en_CA/en_CA/C/en_CA/en_CA.UTF-8"
>>> "320" > "300"
>> [1] NA
>>> "320" > "300"
>> [1] TRUE
>>
>> The first string comparison after the locale change produces NA, while
>> later ones are fine.
>>
> 
> I see the similar things on R version 3.2.0 Patched (2015-05-11 r68355)
> 
>> Sys.setlocale(locale="en_CA")
> [1] "en_CA/en_CA/en_CA/C/en_CA/en_GB"
>> "320" > "300"
> [1] NA
>> "320" > "300"
> [1] TRUE
> 


I've been looking at the Sys.setlocale source.  It resets the collator.
 When the collator is renewed during the comparison, errno is set to 2,
and that results in an NA value for the comparison.

The particular call that sets errno is ucol_open, in Scollate in
src/main/util.c.  The string comparison function in src/main/relop.c
sets errno to 0, then does the comparison, but errno ends up equal to 2
at the end.  Looks easy to fix.

Duncan Murdoch



More information about the R-SIG-Mac mailing list