I have a file that consists of an XML character header and binary data, which is then read using readBinR in:
zz <- file('myfile', 'rb')
x <- readBin(zz, 'character')
...
However, when the header exceeds 10,000 bytes, I get the following:
Warning message:
In readBin(zz, 'character') :
null terminator not found: breaking string at 10000 bytes
I tried to loop until the line matches the end of the header and then concatenates the lines together, but then the XML will not be checked, as some parts have damaged endings (for example, \xa0W\x97^\xff\177added at the end).
How should I work with a character prefix readBin- are there any simple workarounds?
Any suggestions are welcome. Thank!
UPDATE
The following is a reproducible example:
url <- 'http://www.enetpulse.com/wp-content/uploads/sample_xml_feed_enetpulse_icehockey.xml'
x <- paste(readLines(url), collapse = '\n')
f <- tempfile()
zz <- file(f, 'wb')
writeBin(x, zz)
writeBin(1:10000, zz)
close(zz)
zz <- file(f, 'rb')
y <- readBin(zz, 'character')
y
close(zz)
zz <- file(f, 'rb')
readChar(zz, nchars = 999999)
close(zz)
library(XML)
p <- xmlParse(x)
zz <- file(f, 'rb')
fun <- function(x) readBin(zz, 'character')
res <- paste(sapply(1:4, fun), collapse = '')
p2 <- xmlParse(res) # errors!