From murdoch.duncan at gmail.com  Fri Feb  4 14:52:32 2011
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Fri, 04 Feb 2011 08:52:32 -0500
Subject: [Rd] Strange behaviour of read and writeBin
In-Reply-To: <4D4BD675.9060206@uni-muenster.de>
References: <4D4BD675.9060206@uni-muenster.de>
Message-ID: <4D4C04A0.5050203@gmail.com>

On 04/02/2011 5:35 AM, Christian Ruckert wrote:
> To me it seems like writeBin() writes one char/byte more than expected.

You want writeChar rather than writeBin to avoid the null termination of 
strings.

Duncan Murdoch

>   >  con<- file("testbin", "wb")
>   >  writeBin("ttccggaa", con)
>   >  close(con)
>
>   >  con<- file("testbin", "rb")
>   >  readBin(con, what="character")
> [1] "ttccggaa"
>   >  seek(con, what=NA)
> [1] 9
>   >  close(con)
>
>   >  con<- file("testbin", "rb")
>   >  readBin(con, what="raw", n=20)
> [1] 74 74 63 63 67 67 61 61 00
>   >  seek(con, what=NA)
> [1] 9
>   >  close(con)
>
> As the numbering starts with 0 the position should be 8 and not 9 after
> reading. There were two older threads which look very similar to my problem:
>
> http://tolstoy.newcastle.edu.au/R/e2/devel/06/11/1119.html
> http://r.789695.n4.nabble.com/Re-Problem-reading-binaries-created-with-fortran-More-infos-td974396.html
>
> Thanks in advance,
> Christian
>
>
>
>   >  sessionInfo()
> R version 2.12.0 (2010-10-15)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
> [1] C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] Biostrings_2.18.2 IRanges_1.8.8
>
> loaded via a namespace (and not attached):
> [1] Biobase_2.10.0
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Strange behaviour of read and writeBin
Duncan Murdoch