hdf5_remove: Remove (delete) a dataset from an HDF5 file

View source: R/S3_standalone.R

hdf5_removeR Documentation

Remove (delete) a dataset from an HDF5 file

Description

Deletes a dataset from an HDF5 file, given the file path and the full internal dataset path ("group/name"). No open HDF5Matrix object is required. If you already have an open HDF5Matrix, you can equivalently call its $remove() method.

Usage

hdf5_remove(filename, dataset)

Arguments

filename

Path to the HDF5 file.

dataset

Full internal path of the dataset to remove, in the form "group/name" (e.g. "data/matrix" or "grp/sub/matrix").

Details

Space is not reclaimed. HDF5 only unlinks the dataset: the link is removed so the dataset can no longer be opened, but the disk space it occupied is not returned to the operating system until the file is rewritten. To physically reclaim the space, repack the file with the HDF5 command-line tool, e.g. h5repack old.h5 new.h5, or copy the datasets you want to keep into a fresh file. Consequently, repeatedly creating and removing datasets in the same file can make it grow on disk even though the logical contents shrink.

Removing a dataset that does not exist raises an error.

Value

TRUE invisibly on success.

See Also

hdf5_matrix, hdf5_create_matrix, list_datasets

Examples


fn <- tempfile(fileext = ".h5")
hdf5_create_matrix(fn, "grp/keep", data = matrix(1:6, 2, 3))
hdf5_create_matrix(fn, "grp/tmp",  data = matrix(1:6, 2, 3))
hdf5_remove(fn, "grp/tmp")
list_datasets(fn, group = "grp")   # only "keep" remains
hdf5_close_all()
unlink(fn)



BigDataStatMeth documentation built on Sept. 15, 2026, 1:08 a.m.