View source: R/delarr-backends.R
| delarr_mmap | R Documentation |
Uses the mmap package to lazily read slices from a binary file on demand. The file must contain raw numeric data in column-major order (R's default).
delarr_mmap(path, nrow, ncol, mode = NULL)
path |
Path to the binary file containing matrix data. |
nrow |
Number of rows in the matrix. |
ncol |
Number of columns in the matrix. |
mode |
mmap mode object specifying data type. Default is double(). |
A delarr that streams data from the memory-mapped file.
This backend supports 2D matrices only. For N-d arrays, use
delarr_hdf5() or wrap an in-memory array with delarr().
if (requireNamespace("mmap", quietly = TRUE)) {
# Create a binary file with matrix data
mat <- matrix(1:20, nrow = 4, ncol = 5)
tf <- tempfile()
writeBin(as.double(mat), tf)
# Load as delayed array
darr <- delarr_mmap(tf, nrow = 4, ncol = 5)
darr
# Apply operations and collect
result <- darr |> d_map(~ .x * 2) |> collect()
result
# Clean up
unlink(tf)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.