Reputation: 1293
I have a binary file with size=2. But I want to read all the data into a vector and I don't how to find the total length of this binary data.
f <- file("a.bin", "rb")
readBin(f, integer(), size = 2, n = ??)
Upvotes: 4
Views: 3078
Reputation: 176698
Use x <- scan("a.bin", raw())
to read the entire file into a raw vector, then use y <- readBin(x, integer(), n=length(x), size=2)
to convert the raw vector.
Each element in a raw vector is 4 bytes, so you may need to do some conversion to calculate the correct value for n
.
Upvotes: 1