Title: | Memory-Map Character Files |
---|---|
Description: | Uses memory-mapping to enable the random access of elements of a text file of characters separated by characters as if it were a simple R(cpp) matrix. |
Authors: | Florian Privé [aut, cre] |
Maintainer: | Florian Privé <[email protected]> |
License: | GPL-3 |
Version: | 0.3.0 |
Built: | 2024-11-10 05:01:52 UTC |
Source: | https://github.com/privefl/mmapcharr |
Number of lines and columns of file (and extra 'return' characters).
dim_file(file)
dim_file(file)
file |
Path to file. |
The number of lines and columns of file (and extra 'return' characters).
tmpfile <- tempfile() write(0:9, tmpfile, ncolumns = 2) dim_file(tmpfile)
tmpfile <- tempfile() write(0:9, tmpfile, ncolumns = 2) dim_file(tmpfile)
extract
is a function that converts different index types such as negative
integer vectors or logical vectors passed to the [
function as i
(e.g. X[i]
) or i
and j
(e.g. X[i, j]
) into positive
integer vectors. The converted indices are provided as the i
parameter of
extract_vector
or i
and j
parameters of extract_matrix
to facilitate
implementing the extraction mechanism for custom matrix-like types.
Extract(extract_vector, extract_matrix)
Extract(extract_vector, extract_matrix)
extract_vector |
A function in the form of |
extract_matrix |
A function in the form of |
The custom type must implement methods for dim
for this function
to work. Implementing methods for nrow
and ncol
is not necessary
as the default method of those generics calls dim
internally.
This idea initially comes from package crochet.
A function in the form of function(x, i, j, ..., drop = TRUE)
that
is meant to be used as a method for [
for a custom type.
A reference class for storing and accessing matrix-like data stored on disk in files containing only characters (digits) separated by a character.
mmapchar(file, code)
mmapchar(file, code)
file |
Path of the file. |
code |
Integer vector of size 256 to access integers instead of
|
test_file <- system.file("testdata/test-windows.txt", package = "mmapcharr") test <- mmapchar(test_file, code = mmapcharr:::CODE_012) test[, 1:3] test[] readLines(test_file)
test_file <- system.file("testdata/test-windows.txt", package = "mmapcharr") test <- mmapchar(test_file, code = mmapcharr:::CODE_012) test[, 1:3] test[] readLines(test_file)
Methods for the mmapchar class
Accessor methods for class mmapchar
. You can use positive and negative indices,
logical indices (that are recycled) and also a matrix of indices (but only
positive ones).
Dimension and type methods for class mmapchar
.
## S4 method for signature 'mmapchar' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mmapchar' dim(x) ## S4 method for signature 'mmapchar' length(x)
## S4 method for signature 'mmapchar' x[i, j, ..., drop = TRUE] ## S4 method for signature 'mmapchar' dim(x) ## S4 method for signature 'mmapchar' length(x)
x |
A mmapchar object. |
i |
A vector of indices (or nothing). You can use positive and negative indices, logical indices (that are recycled) and also a matrix of indices (but only positive ones). |
j |
A vector of indices (or nothing). You can use positive and negative indices, logical indices (that are recycled). |
... |
Not used. Just to make nargs works. |
drop |
Whether to delete the dimensions of a matrix which have one dimension equals to 1. |
Number of elements of each line of a file.
nelem(file)
nelem(file)
file |
Path to file. |
The number of elements of each line of a file.
tmpfile <- tempfile() write(1:10, tmpfile, ncolumns = 2) nline(tmpfile)
tmpfile <- tempfile() write(1:10, tmpfile, ncolumns = 2) nline(tmpfile)
Number of lines of a file.
nline(file)
nline(file)
file |
Path to file. |
The number of lines of the file.
tmpfile <- tempfile() write(1:5, tmpfile, ncolumns = 1) nline(tmpfile)
tmpfile <- tempfile() write(1:5, tmpfile, ncolumns = 1) nline(tmpfile)