From r|p|ey @end|ng |rom @t@t@@ox@@c@uk  Mon Feb  8 17:47:42 2021
From: r|p|ey @end|ng |rom @t@t@@ox@@c@uk (Prof Brian Ripley)
Date: Mon, 8 Feb 2021 16:47:42 +0000
Subject: [Rd] Does type raw really have no ordering?
In-Reply-To: <CAJmOi+PZKcmr88eAVT0b+iAKkfwtbhjUzuk3SNeJMZ6TJMHX5g@mail.gmail.com>
References: <CAJmOi+PZKcmr88eAVT0b+iAKkfwtbhjUzuk3SNeJMZ6TJMHX5g@mail.gmail.com>
Message-ID: <e19ab2f5-1790-b38e-e00c-eff8717ad41d@stats.ox.ac.uk>

On 08/02/2021 13:25, Hugh Parsonage wrote:
> In the help for Extremes  ?min
> 
>> Note that all versions fail for raw and complex vectors since these have no ordering.
> 
> This makes sense for complex vectors, yet `raw` vectors seem to have a
> natural order. Indeed:
> 
> which.min(as.raw(c(5L, 2L, 1L, 99L)))
> 
> works and would identify the minimum.  Similarly comparison operators
> work on raw vectors (and fail, expectedly, on complex ones).
> 
> Is there something peculiar to min() and friends that make raw vectors
> invalid input?

Please re-read the help for which.min: as it says you computed on an 
internal coercion to double.  Doubles do have an ordering.

Like factors, raw vectors have numeric codes, but that does not imply 
that the ordering of the numeric codes is relevant to the original 
object.  And reading the help for comparisons would have informed you

      Raw vectors should not really be considered to have an order, but
      the numeric order of the byte representation is used.

One use case for a raw vector is to store bytes in an unspecified 8-bit 
encoding.  What ordering would be relevant depends on the encoding - 
this is even true for the ASCII subset - some people sort AaBb some 
AB...ab and some locales even sort aAbB (although I have never seen that 
recommended for human usage).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford



[Rd] Does type raw really have no ordering?
Prof Brian Ripley