[Rd] raw connections: reading does not alter current position pointer

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu May 12 12:13:27 CEST 2011


I am not the author, but looking at the code shows that raw_read has a 
line missing compared to raw_write.

It should work now in R-devel/R-patched.

Thanks for the report.

On Mon, 2 May 2011, William Dunlap wrote:

> Am I misunderstanding rawConnections here or are
> rawConnections not working right yet?  It looks
> like I can use seek() to position the read pointer
> but readBin does not position the read pointer past
> what has just been read.
>
>  > myRawTen <- as.raw(101:110)
>  > str(myRawTen)
>   raw [1:10] 65 66 67 68 ...
>  > rawToChar(myRawTen)
>  [1] "efghijklmn"
>  > myRawTenCon <- rawConnection(myRawTen)
>  > readBin(myRawTenCon, what="integer", size=2, n=1)
>  [1] 26213
>  > c(26213%%256, 26213%/%256)
>  [1] 101 102
>  > # next 2-byte integer should be 104*256 + 103 = 26727
>  > readBin(myRawTenCon, what="integer", size=2, n=1)
>  [1] 26213
>  > # if I seek() explicitly it works
>  > seek(myRawTenCon, 2)
>  [1] 6
>  > readBin(myRawTenCon, what="integer", size=2, n=1)
>  [1] 26727
>
>  > seek(myRawTenCon, 6) # look at last 4 bytes: 107:110
>  [1] 0
>  > # multiple reads in one call to readBin do not advance
>  > # the position pointer:
>  > readBin(myRawTenCon, what="integer", size=1, n=4)
>  [1] 107 107 107 107
>
>  > sessionInfo()
>  R version 2.13.0 (2011-04-13)
>  Platform: i386-pc-mingw32/i386 (32-bit)
>
>  locale:
>  [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252    LC_MONETARY=English_United States.1252
>  [4] LC_NUMERIC=C                           LC_TIME=English_United
> States.1252
>
>  attached base packages:
>  [1] stats     graphics  grDevices utils     datasets  methods   base
>
>
>  other attached packages:
>  [1] lattice_0.19-23 MASS_7.3-12
>
>  loaded via a namespace (and not attached):
>  [1] compiler_2.13.0 grid_2.13.0     tools_2.13.0
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list