View source: R/S3_conversion.R
| as.matrix.HDF5Matrix | R Documentation |
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.
## S3 method for class 'HDF5Matrix'
as.matrix(x, force = FALSE, max_size_mb = NULL, ...)
x |
An |
force |
Logical. If |
max_size_mb |
Numeric. Maximum size in MB to convert without warning.
Default is |
... |
Additional arguments (currently unused) |
Size thresholds and behavior:
Convert silently
Show warning, require confirmation
Show error, require force=TRUE
Block conversion even with force=TRUE
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:
For large datasets, use subsetting instead: X[1:1000, ]
For analysis, use HDF5Matrix methods directly (they work on-disk)
Only convert to memory when absolutely necessary
Standard R matrix with data from HDF5 file
[.HDF5Matrix for subsetting,
as.data.frame.HDF5Matrix for data frame conversion
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.