[R] Decoding raw vectors every other byte

From: Alex van der Spek <doorz_at_xs4all.nl>
Date: Wed, 16 Jun 2010 13:15:43 +0200


I have to decode raw vectors read from a connection like this:

+++++++++++++++++++

fl<-file.choose()
fb<-file.info(fl)$size

fc<-file(fl)
open(fc,open='rb')
seek(fc,where=offset)
dat<-readBin(fc,'raw',n=(fb-offset),size=1,signed=FALSE) close(fc)
++++++++++++++++++

The decoding performs a combination of a simple bitwise operator and a simple arithmatic operator on every other byte in the raw vector dat.

I can code this using a for loop (incrementing the loop counter by 2 every pass) but would rather use vectorized operations for reasons of speed. I can create a function with a for loop and vectorize that function but is there perhaps an easier way to write this? It is enough if this works on windows only. No need to worry about endianness.

Thanks in advance.
Alex van der Spek



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 16 Jun 2010 - 11:18:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Jun 2010 - 11:50:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive