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

Sven Garbade garbade at psy.uni-muenchen.de
Mon Oct 7 20:43:34 CEST 2002


ripley at stats.ox.ac.uk writes:
 > I suspect your interpolation produces numeric not integer vectors.  size=2
 > does not exist for numeric (aka double) vectors.

Yes, that was it.

 > 
 > I really don't understand why this was not obvious!  How did you expect
 > numeric data to be output in two bytes?

The unexpected thing was that the data was sometimes numeric and
sometimes integer. I need the output in two bytes because of some old
DOS programms some of us still use.

Bye, Sven

 > 
 > On Mon, 7 Oct 2002, Sven Garbade wrote:
 > 
 > > 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
 > > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
 > >
 > 
 > -- 
 > 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 272860 (secr)
 > Oxford OX1 3TG, UK                Fax:  +44 1865 272595
 > 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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