- data_bin = file(data_bin_file, "rb")
- data_size = file.info(data_bin_file)$size
- data_length = readBin(data_bin, "integer", n=1, size=8, endian=endian)
- #Ou t(sapply(...)) (+ rapide ?)
- data_ascii = do.call( rbind, lapply( indices, function(i) {
- offset = 8+(i-1)*data_length*nbytes
- if (offset > data_size)
- return (vector("double",0))
- ignored = seek(data_bin, offset)
+ data_bin <- file(data_bin_file, "rb") #source binary file
+
+ data_size <- file.info(data_bin_file)$size #number of bytes in the file
+ # data_length: length of a vector in the binary file (first element, 8 bytes)
+ data_length <- readBin(data_bin, "integer", n=1, size=8, endian=endian)
+
+ # Seek all 'indices' columns in the binary file, using data_length and nbytes
+ # to compute the offset ( index i at 8 + i*data_length*nbytes )
+ data_ascii <- do.call( cbind, lapply( indices, function(i) {
+ offset <- 8+(i-1)*data_length*nbytes
+ if (offset >= data_size)
+ return (NULL)
+ ignored <- seek(data_bin, offset) #position cursor at computed offset