[R] Error in writeBin(object, con, size = 2)

Sven Garbade garbade at psy.uni-muenchen.de
Mon Oct 7 15:23:54 CEST 2002

Hi all,

I wrote a function (in R batch mode) which reads binary data,
interpolates sometimes and wrote a new binary file of the same size as
the input file. Her is a bit of code:

while (length( head <- readBin(si, integer(), 64, size=2))) {
      data <- readBin(si, integer(), head[5], size=2)
      ## now write head to new file
      writeBin(head, so, size=2)
      ## if head[4] is 9 or 10, interpolate 
      if(head[4] == 9 | head[4] == 10) 
        ## interpolate data
        data <-int(data)
      writeBin(data, so, size=2)

si and so are the binary in- and output connections, "int()"
interpolates between some data segments and returns a numeric vector
of the same length as the input vector. 

However, if the data were interpolated, the execution stops with the
follwing error:

Error in writeBin(data, so, size = 2) : That size is unknown on this machine
Execution halted

This error only occured, if "int()" was called before
writeBin(). int() returns a numeric vector with integers.

With writeBin(data, so) everything works, but this gives the wrong
bytes per element in the byte stream.

Any suggestions?
Thanks, Sven

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list