Description Usage Arguments Fields Class-Based Methods Author(s) See Also Examples
A Producer
-class to interpret files as raw
(binary) data. Users interact with this class through the constructor
RawInput
and methods yield
,
reset
, and Stream
.
This class requires two helper functions; the ‘factory’ methods
defined on this page can be used to supply these.
rawReaderFactory
creates a ‘reader’, whose
responsibility it is to accept a connection and return a vector of
predefined type, e.g., raw
. rawParserFactory
creates
a ‘parser’, responsible for parsing a buffer and vector of the
same type as produced by the reader into records. The final record may
be incomplete (e.g., because reader
does not return complete
records), and regardless of completion status is the content of
buf
on the subsequent invocation of
parser
. length(buf)
or length(bin)
may be 0, as
when the first or final record is parsed.
1 2 3 4 | RawInput(con, yieldSize = 1e+06, reader = rawReaderFactory(),
parser = rawParserFactory(), ...)
rawReaderFactory(blockSize = 1e+06, what)
rawParserFactory(separator = charToRaw("\n"), trim = separator)
|
con |
A character string or connection (opened as |
yieldSize |
The number of records the input parser is to yield. |
reader |
A function of one argument ( |
parser |
A function of two arguments ( |
... |
Additional arguments, passed to the |
blockSize |
The number of bytes to read at one time. |
what |
The type of data to read, as the argument to
|
separator |
A |
trim |
A |
con
:Object of class connection
. An R
connection
opened in “rb” mode from which
data will be read.
blockSize
:Object of class integer
. Size
(e.g., number of raw bytes) input during each
yield
.
reader
:Object of class function
. A function
used to input blockSize
elements. See
rawReaderFactory
.
parser
:Object of class function
. A function
used to parse raw input into records, e.g., breaking a
raw
vector on new lines ‘\n’. See
rawParserFactory
.buffer
:Object of class raw
. Contains read but
not parsed raw stream data.
.records
:Object of class list
. Parsed but not
yet yield-ed records.
.parsedRecords
:Object of class integer
. Total
number of records parsed by the Producer.
reset()
:Remove buffer and current records, reset
record counter, re-open con
.
Martin Morgan mtmorgan@fhcrc.org
1 2 3 4 5 | fl <- system.file("extdata", "s_1_sequence.txt", package="Streamer")
b <- RawInput(fl, 100L, reader=rawReaderFactory(1e4))
length(value <- yield(b))
head(value)
close(b)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.