delarr_seed: Construct a seed backend for 'delarr'

View source: R/delarr-seed.R

delarr_seedR Documentation

Construct a seed backend for delarr

Description

Seeds encapsulate storage access for delayed matrices. They define matrix dimensions and a pull() function that returns materialised slices.

Usage

delarr_seed(
  nrow,
  ncol,
  pull,
  chunk_hint = NULL,
  dimnames = NULL,
  begin = NULL,
  end = NULL
)

Arguments

nrow, ncol

Number of rows and columns.

pull

A function accepting rows and cols indices and returning a base matrix slice.

chunk_hint

Optional list describing preferred chunk sizes (e.g. list(cols = 4096L)).

dimnames

Optional list of dimnames to expose lazily.

begin

Optional function invoked before streaming begins.

end

Optional function invoked after streaming completes.

Value

An object of class delarr_seed.

Examples

# Create a custom seed with a pull function
data <- matrix(1:12, nrow = 3, ncol = 4)

seed <- delarr_seed(
  nrow = 3,
  ncol = 4,
  pull = function(rows = NULL, cols = NULL) {
    rows <- rows %||% seq_len(3)
    cols <- cols %||% seq_len(4)
    data[rows, cols, drop = FALSE]
  }
)
seed

# Wrap in delarr() to use with lazy operations
darr <- delarr(seed)
result <- darr |> d_map(~ .x * 2) |> collect()
result

delarr documentation built on July 1, 2026, 1:06 a.m.