% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/S3_conversion.R
\name{as.matrix.HDF5Matrix}
\alias{as.matrix.HDF5Matrix}
\title{Convert HDF5Matrix to in-memory matrix}
\usage{
\method{as.matrix}{HDF5Matrix}(x, force = FALSE, max_size_mb = NULL, ...)
}
\arguments{
\item{x}{An \code{HDF5Matrix} object}

\item{force}{Logical. If \code{TRUE}, skip size warnings. Default \code{FALSE}.}

\item{max_size_mb}{Numeric. Maximum size in MB to convert without warning.
Default is \code{NULL} (auto-detect based on system RAM). Use \code{Inf} to disable.}

\item{...}{Additional arguments (currently unused)}
}
\value{
Standard R matrix with data from HDF5 file
}
\description{
Reads entire HDF5 dataset into memory as a standard R matrix.
\strong{WARNING}: This loads all data into RAM. For large datasets (>1GB),
this may cause memory exhaustion.
}
\details{
\strong{Size thresholds and behavior:}

\describe{
\item{Small datasets (< max_size_mb):}{Convert silently}
\item{Medium datasets (max_size_mb to 2GB):}{Show warning, require confirmation}
\item{Large datasets (> 2GB):}{Show error, require force=TRUE}
\item{Huge datasets (> 8GB):}{Block conversion even with force=TRUE}
}

\strong{Memory estimation:}
The function estimates memory usage as:
\code{nrow * ncol * 8 bytes (for numeric)}

Actual memory usage may be higher due to:
\itemize{
\item R's internal overhead
\item Temporary copies during conversion
\item Other objects in memory
}

\strong{Recommendations:}
\itemize{
\item For large datasets, use subsetting instead: \code{X[1:1000, ]}
\item For analysis, use HDF5Matrix methods directly (they work on-disk)
\item Only convert to memory when absolutely necessary
}
}
\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)
}

}
\seealso{
\code{\link{[.HDF5Matrix}} for subsetting,
\code{\link{as.data.frame.HDF5Matrix}} for data frame conversion
}
