BinaryFiles: Binary files

Description Usage Arguments Author(s) Examples

Description

Save/read a fortran-formatted binary file that was saved at a defined precision (single or double).

Usage

1
2
3
4
5
saveBinary(X, filename = paste0(tempdir(), "/file.bin"), 
  row.names = TRUE, col.names = TRUE, size = 4, verbose = TRUE)
  
readBinary(filename = paste0(tempdir(), "/file.bin"), 
  indexRow = NULL, indexCol = NULL, verbose = TRUE)

Arguments

X

Numeric matrix to save

filename

Name of the binary file to save/read

row.names

TRUE or FALSE to whether save rows names

col.names

TRUE or FALSE to whether save columns names

size

Size of a real variable in bytes (size=4 for single precision and size=8 for double precision) that matrix to be saved X will occupy

indexRow

Vector of integers indicating the rows to be read from the file. Default indexRow=NULL will read all the rows

indexCol

Vector of integers indicating the columns to be read from the file. Default indexCol=NULL will read all the columns

verbose

TRUE or FALSE to whether printing file information

Author(s)

Marco Lopez-Cruz (lopezcru@msu.edu) and Gustavo de los Campos

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  require(SFSI)
  data(wheatHTP)

  # Save matrix
  saveBinary(X,paste0(tempdir(),"/Matrix1.bin"),size=4)  # as single-precision
  saveBinary(X,paste0(tempdir(),"/Matrix2.bin"),size=8)  # as double-precision

  # Read the single-precision matrix
  X2 = readBinary(paste0(tempdir(),"/Matrix1.bin"))
  X2[1:10,1:5]
  sum(abs(X-X2))   # Note the loss of precision

  # Read the double-precision matrix
  X2 = readBinary(paste0(tempdir(),"/Matrix2.bin"))
  X2[1:10,1:5]
  sum(abs(X-X2))   # No loss of precision

  # Read specific rows and columns
  indexRow = c(2,4,5,8,10)
  indexCol = c(1,2,6,7,10)
  X2 = readBinary(paste0(tempdir(),"/Matrix2.bin"),indexRow=indexRow,indexCol=indexCol)
  X2
  sum(abs(X[indexRow,indexCol]-X2))

MarcooLopez/SFSI_data documentation built on April 15, 2021, 10:53 a.m.