From jon.clayden at gmail.com  Mon Apr 28 12:15:16 2008
From: jon.clayden at gmail.com (Jon Clayden)
Date: Mon, 28 Apr 2008 11:15:16 +0100
Subject: [Rd] R 2.7.0, match() and strings containing \0 - bug?
In-Reply-To: <68e086180804280300k67057773yc7e8003259c6c6cf@mail.gmail.com>
References: <68e086180804280300k67057773yc7e8003259c6c6cf@mail.gmail.com>
Message-ID: <68e086180804280315j55ec0018iaf3a67ab96570b0@mail.gmail.com>

Apologies for missing out the sessionInfo():

R version 2.7.0 (2008-04-22)
i386-apple-darwin8.10.1

locale:
en_GB.UTF-8/en_US.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base


2008/4/28 Jon Clayden <jon.clayden at gmail.com>:
> Hi,
>
>  A piece of my code that uses readBin() to read a certain file type is
>  behaving strangely with R 2.7.0. This seems to be because of a failure
>  to match() strings after using rawToChar() when the original was
>  terminated with a "\0" character. Direct equality testing with ==
>  still works as expected. I can reproduce this as follows:
>
>  > x <- "foo"
>  > y <- c(charToRaw("foo"),as.raw(0))
>  > z <- rawToChar(y)
>  > z==x
>  [1] TRUE
>  > z=="foo"
>  [1] TRUE
>  > z %in% c("foo","bar")
>  [1] FALSE
>  > z %in% c("foo","bar","foo\0")
>  [1] FALSE
>
>  But without the nul character it works fine:
>
>  > zz <- rawToChar(charToRaw("foo"))
>  > zz %in% c("foo","bar")
>  [1] TRUE
>
>  I don't see anything about this in the latest NEWS, but is this
>  expected behaviour? Or is it, as I suspect, a bug? This seems to be
>  new to R 2.7.0, as I said.
>
>  Regards,
>  Jon
>



[Rd] R 2.7.0, match() and strings containing \0 - bug?
Jon Clayden