as.matrix.HDF5Matrix

as.matrix.HDF5Matrix

OTHER

1 Description

Reads entire HDF5 dataset into memory as a standard R matrix. WARNING: This loads all data into RAM. For large datasets (>1GB), this may cause memory exhaustion.

2 Usage

as.matrix.HDF5Matrix(x, force = FALSE, max_size_mb = NULL, ...)

3 Arguments

Parameter Description
x An object
force Logical. If , skip size warnings. Default .
max_size_mb Numeric. Maximum size in MB to convert without warning. Default is (auto-detect based on system RAM). Use to disable.

4 Value

Standard R matrix with data from HDF5 file

5 Details

Size thresholds and behavior:

Memory estimation: The function estimates memory usage as: nrow * ncol * 8 bytes (for numeric)

Actual memory usage may be higher due to: - R’s internal overhead - Temporary copies during conversion - Other objects in memory

Recommendations:

6 Examples

\donttest{
    fn <- tempfile(fileext = ".h5")
    X <- hdf5_create_matrix(fn, "data/X", data = matrix(rnorm(500), 100, 5))
    mat <- as.matrix(X)
    head(mat)

    # Subsetting is more efficient for large datasets
    subset <- X[1:10, 1:3]

    hdf5_close_all()
    unlink(fn)
}

7 See Also

[.HDF5Matrix for subsetting, as.data.frame.HDF5Matrix for data frame conversion