[prev in list] [next in list] [prev in thread] [next in thread]
List: r-devel
Subject: Re: [Rd] R 2.7.0, match() and strings containing \0 - bug?
From: Herve Pages <hpages () fhcrc ! org>
Date: 2008-04-28 22:43:00
Message-ID: 481652F4.30706 () fhcrc ! org
[Download RAW message or body]
Hi Jon,
Jon Clayden wrote:
> 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 this gives TRUE:
> z %in% c("foo","bar", z)
[1] TRUE
An additional problem you have here is that when the "foo\0" string literal
is converted into a character string, then the string data that are after the
first embedded nul are dropped:
> identical("foo\0a\0b", "foo")
[1] TRUE
And to add to the endless source of surprises that come with embedded nuls:
> dump("z", file="")
z <-
"foo\0"
but of course sourcing the above dump into an R session will not restore 'z'.
Dropping support for embedded nuls in R 2.8.0 sounds like good news to me.
Cheers,
H.
>
> 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
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic