tsvGetData {tsvio} | R Documentation |
Read matching lines from a tsv file, using a pre-computed index file.
Description
This function reads lines that match the given patterns from a TSV file with the assistance of a pre-computed index file to the start of each row.
Usage
tsvGetData(
filename,
indexfile,
rowpatterns,
colpatterns,
dtype = "",
findany = TRUE
)
Arguments
filename |
The name (and path) of the file containing the data to index. |
indexfile |
The name (and path) of the file to which the index will be written. |
rowpatterns |
A vector of strings containing the string to match against the index entries. Only lines with keys that exactly match at least one pattern string are returned. If rowpatterns is NULL, data from all rows is returned. |
colpatterns |
A vector of strings to match against the column headers in the first row |
dtype |
A prototype element that specifies by example the type of matrix to return. The value of the parameter is ignored. Accepted types are string (default), numeric (float), and integer. |
findany |
If false, all patterns must be matched. If true (default) at least one pattern must match. |
Details
The index file must have been created by tsvGenIndex and the data file must not have changed since the index file was created.
Value
A matrix containing one row for each matched line and one column for each matched column.
See Also
tsvGenIndex, tsvGetLines
Examples
datafile = tempfile("data");
df <- data.frame(C1 = c("Foo", "Boing", "The"), C2 = c("Bar", "Boing", "End"));
rownames(df) <- c("R1", "R2", "R3");
write.table(df, file=datafile, sep="\t", quote=FALSE, row.names=TRUE, col.names=TRUE);
indexfile = tempfile("index");
tsvGenIndex (datafile, indexfile);
tsvGetData (datafile, indexfile, c("R1", "R3"), c('C2'))