delarr_backend: Wrap a custom backend as a delayed matrix

View source: R/delarr-backends.R

delarr_backendR Documentation

Wrap a custom backend as a delayed matrix

Description

Provides a convenience helper that turns a user-supplied slice function into a ready-to-use delarr object.

Usage

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

Arguments

nrow, ncol

Dimensions of the logical matrix.

pull

Function of rows and cols returning a base matrix slice.

chunk_hint

Optional preferred chunking metadata.

dimnames

Optional dimnames to expose lazily.

begin

Optional function invoked before streaming.

end

Optional function invoked after streaming.

Value

A delarr backed by the provided pull function.

Examples

# Create a custom backend from a pull function
data <- matrix(1:20, nrow = 4, ncol = 5)

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

# Use like any delarr
result <- darr |> d_map(~ .x * 2) |> collect()
result

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