[Rd] Strange behaviour of read and writeBin

Christian Ruckert cruckert at uni-muenster.de
Fri Feb 4 11:35:33 CET 2011


To me it seems like writeBin() writes one char/byte more than expected.

 > 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



More information about the R-devel mailing list