Hi there,
I want to read all data from a binary file (with package Rstreams). I
tried the following function (small piece of code):
readdata <- function (file) {
# open file
s <- openstream(file, "read")
# read int values
while (s$position <= s$size) {
readint(s, 1, 2) -> type
[...]
}
return()
}
and got the following error:
> Error in while (s$position <= s$size) { : missing value where logical
needed
Is it possible to read data from the start to the finish of a stream?
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Jun-01 13:44 UTC
[R] Read to the end of a stream (package Rstreams)
Sven Garbade <garbade at psy.uni-muenchen.de> writes:> Hi there, > > I want to read all data from a binary file (with package Rstreams). I > tried the following function (small piece of code): > > readdata <- function (file) { > # open file > s <- openstream(file, "read") > > # read int values > while (s$position <= s$size) { > readint(s, 1, 2) -> type > [...] > } > > return() > } > > and got the following error: > > > Error in while (s$position <= s$size) { : missing value where logical needed > > Is it possible to read data from the start to the finish of a stream?Yes, but not like that. s does not have the position and size components; only summary(s) has those. So while (summary(s)$position < summary(s)$size) {...} would do it (note: at "==", you're at the end). However, it would be more natural to use the fact that readint returns numeric(0) on EOF: while ( length(type <- readint(s, 1, 2)) ) { ... } -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._