Are you really trying to read in binary?  You are asking for
characters which would be a null terminated string.  If you are trying
to read in binary zeroes, this will not work.  What you need to do is
to use 'raw'.  Actually you should create a R script to test out the
various conditions you want.  If you use 'raw', this will read in the
actual bytes in the file.  You can check to see if the length of the
vector is what you requested.  If it is not, then you have reached an
end of file.  It is easy enough to try out the various options to see
what happens.  So if you are trying to read binary, then use 'raw'.
If you are reading null terminated strings, then 'character' will
work.  If your file consists of binary integers, then use 'integer'
and make sure you know if the 'endian' of the data.  There are lots of
other cases/conditions depending on what you are trying to do.

On Sat, Jan 23, 2010 at 10:40 PM, rn00b <forzat...@gmail.com> wrote:
>
> I am using readBin to continuously read characters from the binary file. I'm
> trying to figure out how many characters are in the file. What I would like
> to do is something like
> (while! EOF)
> {
> charRead <-.Internal(readBin(con,"character",1L,NA,TRUE,swap))
> i++
> }
>
> I'm not clear on how to determine the EOF condition in this case.
> --
> View this message in context: 
> http://n4.nabble.com/End-of-File-for-binary-files-tp1288509p1288525.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

______________________________________________
R-help@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.

Reply via email to