readBin
Read and Write Binary Data

Description

Read or write binary data from a connection.

Usage

readBin(con, what, n = 1L, size = NA_integer_, signed = TRUE, 
    endian = .Platform$endian)
writeBin(object, con, size = NA_integer_, 
    endian = .Platform$endian, useBytes = FALSE)

Arguments

con a connection object or a character string naming a file.
object an atomic object to be written to con.
what a character string denoting the mode of the data to be read. Can be one of '"numeric", "double", "integer", "int", "logical", "complex", or "character". Alternatively, what can be an object whose mode is used for the mode of the object to read.
n an integer specifying the maximum number of values to read.
size an integer specifying the number of bytes per value read. The default of NA_integer_ uses a default size for a value of the given mode (4 for integer and single, 8 for double, and 16 for complex: the same for both 32- and 64-bit versions of Spotfire Enterprise Runtime for R). This argument is ignored for character data. Rather, character data is read as null-terminated strings of single byte characters.
signed a logical value. Used only for integers of sizes 1 and 2. If TRUE (the default), integers are regarded as signed integers.
endian a character string. If endian="big" or endian="little", specifies the endian-ness of the values read or written. If endian="swap" the endian-ness is swapped. Intel hardware is "little" endian and Sun hardware is "big" endian.
useBytes a logical value. Ignored by Spotfire Enterprise Runtime for R. In R, if FALSE (the default), specifies that writeBin should convert strings with encodings to a printable string before writing the bytes. If TRUE, specifies that writeBin should write the unconverted string bytes.

Details

If con is a character string, the function creates a file connection to a file of that name.
Value
readBinreturns a vector of the appropriate mode. The length is the number of items read.
writeBinreturns NULL or a raw vector (if con is a raw vector).
Differences between Spotfire Enterprise Runtime for R and Open-source R
See Also
readChar, writeChar, charToRaw, file, scan, .Platform.
Examples
tf <- tempfile()
x <- as.integer(c(-1,1)*3^(0:19))
writeBin(con=tf, x)
readBin(tf, integer(), n=20)
unlink(tf)
Package base version 6.1.1-7
Package Index