Binary files
Save/read a numeric data as a fortran-formatted binary file at a defined precision (single or double).
saveBinary(X, file = paste0(tempdir(), "/file.bin"), row.names = TRUE, col.names = TRUE, type = c("float","double"), verbose = TRUE) readBinary(file = paste0(tempdir(), "/file.bin"), indexRow = NULL, indexCol = NULL, verbose = TRUE)
X |
(numeric matrix) Data to save |
file |
(character) Name of the binary file to save/read |
row.names |
|
col.names |
|
type |
(character) Either 'float' or 'double' for single (4 bytes) or double precision (8 bytes), respectively, that matrix to save will occupy |
indexRow |
(integer vector) Which rows are to be read from the file. Default |
indexCol |
(integer vector) Which columns are to be read from the file. Default |
verbose |
|
Function 'saveBinary' does not return any value but print a description of the file saved.
Function 'readBinary' returns the data that was read.
Marco Lopez-Cruz (maraloc@gmail.com) and Gustavo de los Campos
require(SFSI) # Simulate matrix n = 1000; m = 5 X = matrix(rnorm(n*m),ncol=m) head(X) # Save matrix saveBinary(X,paste0(tempdir(),"/Matrix1.bin"),type="double") # as double-precision saveBinary(X,paste0(tempdir(),"/Matrix2.bin"),type="float") # as single-precision # Read the double-precision matrix X2 = readBinary(paste0(tempdir(),"/Matrix1.bin")) head(X2) max(abs(X-X2)) # No loss of precision object.size(X2) # Size of the object # Read the single-precision matrix X3 = readBinary(paste0(tempdir(),"/Matrix2.bin")) head(X3) max(abs(X-X3)) # Loss of precision object.size(X3) # But smaller-size object # Read specific rows and columns indexRow = c(2,4,5,8,10) indexCol = c(1,2,5) X2 = readBinary(paste0(tempdir(),"/Matrix1.bin"),indexRow=indexRow,indexCol=indexCol) X2 # Equal to: X[indexRow,indexCol]
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.