# \donttest{
# Check if 1 GB can be safely allocated
if (can_allocate(1)) {
message("1 GB allocation is safe")
} else {
message("Not enough RAM for 1 GB allocation")
}
# Use it to decide how much data to load
fn <- tempfile(fileext = ".h5")
X <- hdf5_create_matrix(fn, "data/M",
data = matrix(rnorm(1000), 100, 10))
size_gb <- prod(dim(X)) * 8 / 1e9 # estimate in GB
if (can_allocate(size_gb)) {
mat <- as.matrix(X)
} else {
mat <- X[1:50, ] # load subset
}
hdf5_close_all()
unlink(fn)
# }
Run the code above in your browser using DataLab