writeHDF5Array {HDF5Array} | R Documentation

## Write an array-like object to an HDF5 file

### Description

A function for writing an array-like object to an HDF5 file.

### Usage

    writeHDF5Array(x, filepath=NULL, name=NULL, chunkdim=NULL, level=NULL,
                   verbose=FALSE)

### Arguments

`x` | The array-like object to write to an HDF5 file. If `x` is a DelayedArray object, `writeHDF5Array` realizes it on disk, that is, all the delayed operations carried by the object are executed while the object is written to disk. See "On-disk realization of a DelayedArray object as an HDF5 dataset" section below for more information.
`filepath` | `NULL` or the path (as a single string) to the (new or existing) HDF5 file where to write the dataset. If `NULL`, then the dataset will be written to the current HDF5 dump file i.e. the path returned by `getHDF5DumpFile` will be used.
`name` | `NULL` or the name of the HDF5 dataset to write. If `NULL`, then the name returned by `getHDF5DumpName` will be used.
`chunkdim` | The dimensions of the chunks to use for writing the data to disk. By default, `getHDF5DumpChunkDim(dim(x), type(x))` is used. See `?getHDF5DumpChunkDim` for more information.
`level` | The compression level to use for writing the data to disk. By default, `getHDF5DumpCompressionLevel()` is used. See `?getHDF5DumpCompressionLevel` for more information.
`verbose` | Set to `TRUE` to make the function display progress.

### Details

Please note that, depending on the size of the data to write to disk and the performance of the disk, `writeHDF5Array` can take a long time to complete. Use `verbose=TRUE` to see its progress.

Use `setHDF5DumpFile` and `setHDF5DumpName` to control the location of automatically created HDF5 datasets.

### Value

An HDF5Array object pointing to the newly written HDF5 dataset on disk.

### On-disk realization of a DelayedArray object as an HDF5 dataset

When passed a DelayedArray object, `writeHDF5Array` realizes it on disk, that is, all the delayed operations carried by the object are executed on-the-fly while the object is written to disk. This uses a block-processing strategy so that the full object is not realized at once in memory. Instead the object is processed block by block i.e. the blocks are realized in memory and written to disk one at a time.

In other words, `writeHDF5Array(x, ...)` is semantically equivalent to `writeHDF5Array(as.array(x), ...)`, except that `as.array(x)` is not called because this would realize the full object at once in memory.

See `?DelayedArray` for general information about DelayedArray objects.

### See Also

- HDF5Array objects.

- `saveHDF5SummarizedExperiment` and `loadHDF5SummarizedExperiment` in this package (the HDF5Array package) for saving/loading an HDF5-based SummarizedExperiment object to/from disk.

- HDF5-dump-management for controlling the location of automatically created HDF5 datasets.

- `h5ls` in the rhdf5 package.

### Examples

    library(rhdf5)
    library(h5vcData)

    tally_file <- system.file("extdata", "example.tally.hfs5",
                              package="h5vcData")
    h5ls(tally_file)

    cov0 <- HDF5Array(tally_file, "/ExampleStudy/16/Coverages")

    cov1 <- cov0[ , , 29000001:29000007]

    out_file <- tempfile()
    writeHDF5Array(cov1, out_file, "cov1")
    h5ls(out_file)

[Package HDF5Array version 1.8.1 Index]