subset-.HDF5Matrix: Subsetting assignment for HDF5Matrix objects

[<-.HDF5MatrixR Documentation

Subsetting assignment for HDF5Matrix objects

Description

Subsetting assignment for HDF5Matrix objects

Usage

## S3 replacement method for class 'HDF5Matrix'
x[i, j, ...] <- value

Arguments

x

An HDF5Matrix object

i

Row indices (numeric, logical, or missing)

j

Column indices (numeric, logical, or missing)

...

Ignored

value

Values to assign (scalar, vector, or matrix)

Details

Writes data to the HDF5 dataset backing the HDF5Matrix object. Supports:

  • Scalar assignment: X[i, j] <- 5

  • Vector assignment: X[i, ] <- c(1, 2, 3)

  • Matrix assignment: X[1:3, 1:3] <- matrix(...)

  • Full replacement: X[] <- matrix(...)

The value is automatically recycled or reshaped to match the target dimensions. Changes are written immediately to disk.

Value

The modified HDF5Matrix object (invisibly)

Examples



tmp <- tempfile(fileext = ".h5")

# Create a matrix
X  <- hdf5_create_matrix(tmp, "data/X", data = matrix(rnorm(100), 10, 10))

X <- hdf5_matrix(tmp, "data/X")

# Assign scalar
X[1, 1] <- 42

# Assign row
X[2, ] <- 1:10

# Assign block
X[1:3, 1:3] <- matrix(0, 3, 3)

hdf5_close_all()
unlink(tmp)



BigDataStatMeth documentation built on May 15, 2026, 1:07 a.m.