[R] Error in writeBin(object, con, size = 2)
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Mon Oct 7 18:25:51 CEST 2002
I suspect your interpolation produces numeric not integer vectors. size=2
does not exist for numeric (aka double) vectors.
I really don't understand why this was not obvious! How did you expect
numeric data to be output in two bytes?
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