readBin(con, what, n=1, size=NA, signed=TRUE, endian=.Platform$endian, output=NULL) writeBin(object, con, size=NA, endian=.Platform$endian)
con
.
what
can be object whose
mode will be used for the mode of the object to be read.
NA
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 on both 32 and 64 bit versions of S-PLUS). When reading
character data this is ignored: character data is read as null-terminated
strings of single byte characters.
TRUE
, integers are regarded as
signed integers.
endian="swap"
the endian-ness will be swapped. Intel hardware is little endian and
Sun hardware is big endian.
what
but used when the type of data in the file is
different than the type of S-PLUS vector used to store the data.
what
refers to the data in the file and
output
refers to the output of
readBin
.
output=double()
is useful for reading unsigned 4 byte integers (so integers bigger
than 2^31 are not read as negative numbers) or even for 8 byte
integers on 32-bit versions of Splus. In the latter case
you may lose some precision, but reading it as 4 byte integers
will omit the 4 high order bytes.
If
con
is a character string, the function will create a file
connection to a file of that name.
readBin
, a vector of the appropriate mode.
The length is the number of items read.
For
writeBin
,
NULL
.
These functions are modeled after the functions of the same name in R.
file
,
scan
,
.Platform
.
tf <- tempfile() x <- as.integer(c(-1,1)*3^(0:19)) writeBin(con=tf, x) readBin(tf, integer(), n=20) unlink(tf)