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

readBin | returns a vector of the appropriate mode. The length is the number of items read.
writeBin | returns NULL or a raw vector (if con is a raw vector).

Differences between Spotfire Enterprise Runtime for R and Open-source R

- In open-source R, the useBytes argument to writeBin specifies whether to write encoded strings in a form that can be printed. For example, if R cannot display Unicode characters, writeBin("\u30A4",f,useBytes=FALSE) would write the bytes for the string "a<U+30A4>;b", whereas writeBin("\u30A4",f,useBytes=TRUE) would write the bytes contained in the string as produced by charToRaw.

- Spotfire Enterprise Runtime for R ignores the useBytes argument, and always writes the string bytes as produced by charToRaw.

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.5-18
Package Index