Re: [Rd] order() fails on a chr object of class "AsIs" with "\265" in it

From: Don MacQueen <>
Date: Mon, 18 Jan 2010 10:21:13 -0800

Prof. Ripley,

Thank you for the explanation. I appreciate both understanding what's happening, and having several options for fixing my scripts.


At 7:17 AM +0000 1/16/10, Prof Brian Ripley wrote:
>On Fri, 15 Jan 2010, Don MacQueen wrote:
>>Here's an example (session info at the end).
>>> tmpv <- c('\265g/L','Bq/L')
>>> order(tmpv)
>>[1] 2 1
>>> tmpv <- I(tmpv)
>>> order(tmpv)
>>Error in if (xi > xj) 1L else -1L : missing value where TRUE/FALSE needed
>>> foov <- gsub('\265','',tmpv)
>>> order(foov)
>>[1] 2 1
>>> str(tmpv)
>>Class 'AsIs' chr [1:2] "\265g/L" "Bq/L"
>>> str(foov)
>>Class 'AsIs' chr [1:2] "g/L" "Bq/L"
>>I can easily work around this in my scripts, but shouldn't order()
>>succeed with such an object?
>Not in the C locale. There is no pre-defined ordering for non-ASCII
>characters in that locale and the string is invalid in a strict C
>>(I suppose this could be Mac-specific, but I'm assuming it's not...)
>No, but the handling of invalid strings in C is OS-specific.
>>For context:
>>The character "\265" causes the Greek letter mu to be displayed in
>>various output devices. For example, the character vector
>>eventually gets written to an html file, which when displayed in
>>Firefox (Mac) is displayed as Greek mu. Also in Excel 2004 (Mac).
>>I first wrote these scripts 6 years ago, when "\265" was a way I
>>could find to display the Greek mu in output text files of various
>>kinds. They worked as recently as 3 months ago. Maybe there's a
>>better way now to display a mu in text-based contexts?
>Use UTF-8 and Unicode \u03BC (http://*www.*
>The issue is that you need a xtfrm method for 'AsIs': it falls back
>to comparisons via .gt and those (correctly) fail.
>xtfrm.AsIs <- function(x) xtfrm(unclass(x))
>would keep get you going until you fix the scripts.
>>> sessionInfo()
>>R version 2.10.1 (2009-12-14)
>>[1] C
>>attached base packages:
>>[1] stats graphics grDevices utils datasets methods base
>>Don MacQueen
>>Environmental Protection Department
>>Lawrence Livermore National Laboratory
>>Livermore, CA, USA
>> mailing list
>Brian D. Ripley,
>Professor of Applied Statistics, http://*www.*
>University of Oxford, Tel: +44 1865 272861 (self)
>1 South Parks Road, +44 1865 272866 (PA)
>Oxford OX1 3TG, UK Fax: +44 1865 272595

Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA

______________________________________________ mailing list
Received on Mon 18 Jan 2010 - 18:24:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Jan 2010 - 01:30:14 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive