Dear Prof Ripley,

You wrote :

> You failed to supply a raw value to match, and if you do it works:
>
>  match(as.raw(2), a)
>>
> [1] 9
>
> for the ninth value is *not* '2, indeed': it is as.raw(2).
>

Thanks for the clarification.

I think you are confusing R objects with their printed representation.
>

   Yes, I must admit. And in this case I was confused by the fact that my
implementation of a replacement function doing a step-by-step search worked
without any need of as.raw()

my_match <- function (needle, hay_stack) {
  for (i in seq(length(hay_stack)))
  {
    if (hay_stack[i] == needle) {
      return(i)
    }
  }
  return(NA)
}

So, even if the ninth value is *not* '2, but as.raw(2), the comparison "a[9]
== 2" is true.


> (In this case values are coerced to strings, and a[9] is thus coerced to
> "02", which is not matched by the integer 02 nor the byte "\002".)
>
>
   OK.  Had I tried "02", it would have worked, but only by chance.

   For my personal guidance, is there a search function that does not coerce
to string, and thus would be faster ?
   (even if I must admit that, currently match(as.raw(), ) is fast enough
and about three times faster than my very naīve replacement).

Bruno.

	[[alternative HTML version deleted]]

