Stream write functions {Rstreams} | R Documentation |
Writes binary data to the current position within a stream.
writeint(stream, data, size = 4, swapbytes = FALSE) writefloat(stream, data, size = 8, swapbytes = FALSE) writecomplex(stream, data, size = 8, swapbytes = FALSE) writechar(stream, data, asciiz = FALSE)
stream |
a stream previously opened in write mode. |
data |
a vector of data to write. |
size |
the size of each item, in bytes. |
swapbytes |
whether to swap the byte order when writing. |
asciiz |
whether to append an ascii zero to each character vector component. |
Integers can be written in sizes of 1, 2, 4, and 8 bytes.
Numeric values can be written as float
, double
or
long double
.
Any size of character string that you can create can be written.
If swapbytes = TRUE
, then when writing any multi-byte numbers, the
byte order within the number will be swapped. This allows you to write
data for a machine that uses a different convention for numeric storage,
i.e. write little-endian data from a big-endian machine, or vice versa.
If asciiz = FALSE
(the default), there is no separator between the
components of a character vector being written.
none
sampledata <- 1:100 s <- openstream("mydata", "write") # Write the bytes from 1 to 100 to the file writeint(s, sampledata, 1) closestream(s) unlink("mydata")