From spencer.graves at prodsyse.com  Sun Jul 10 17:26:35 2011
From: spencer.graves at prodsyse.com (Spencer Graves)
Date: Sun, 10 Jul 2011 08:26:35 -0700
Subject: [Rd] sort infelicity
In-Reply-To: <BEAC23EE-E846-4ABE-A820-0368062A0112@gmail.com>
References: <4E192015.5030305@prodsyse.com>
	<BEAC23EE-E846-4ABE-A820-0368062A0112@gmail.com>
Message-ID: <4E19C4AB.9050805@prodsyse.com>

       Thanks to Professors Ripley and Dalgaard for explaining the problem.


       In this case, I actually looked at the help page for "sort" but 
didn't see an option in the argument string that suggested a source for 
the problem:  I saw no argument like locale=getOption('locale').  I 
fixed the problem, as suggested, by sorting the theoretical answer 
before stopifnot(all.equal(...)).


       Thanks again,
       Spencer Graves


On 7/10/2011 12:03 AM, peter dalgaard wrote:
> On Jul 10, 2011, at 05:44 , Spencer Graves wrote:
>
>> Hello:
>>
>>
>>       sort(c('A', 'b', 'C')) seems to produce different answers in R interactive than in "R CMD check", at least under both Fedora 13 and Windows 7 with Windows 7 sessionInfo() copied below:
>>
>>
>>       In interactive, the result is c('A', 'b', 'C');  with R CMD check, it is c('A', 'C', 'b').  This produced the infelicity of a bug in "R CMD check" that I could not replicate with interactive R because a *.Rd file contained the equivalent example of stopifnot(all.equal(sort(c('A', 'b', 'C')), c('A', 'b', 'C'))):  It worked just fine interactively but failed R CMD check.
>>
>>
>>       Once I understood this problem, it was easy to fix.  However, it was not easy to find, especially since I got the same problem under Fedora 13 Linux and Windows 7.
>>
>>
>>       This seems to be a sufficiently obscure anomaly that I thought someone might like to see it reported here.
>>
> Well, the problem is here:
> [snip]
>> locale:
>> [1] LC_COLLATE=English_United States.1252
> ==========================================
>> [2] LC_CTYPE=English_United States.1252
>> [3] LC_MONETARY=English_United States.1252
>> [4] LC_NUMERIC=C
>> [5] LC_TIME=English_United States.1252
> All checks in R (unless we overlooked some) run with LC_COLLATE=C, because otherwise they give different results in different locales. One notorious example is that people expect that a file or an object called "zzz" comes out last in a sort, but Estonian sorts "z" between "s" and "t"...
>
> Notice that your .Rd example would, for the same reason, break for people with different locale settings.



[Rd] sort infelicity
Spencer Graves