h5_read | R Documentation |
Reads objects in HDF5 files. This function can be used to read either full arrays/vectors or subarrays (hyperslabs) from an existing dataset.
h5read(
file,
name,
index = NULL,
start = NULL,
stride = NULL,
block = NULL,
count = NULL,
compoundAsDataFrame = TRUE,
callGeneric = TRUE,
read.attributes = FALSE,
drop = FALSE,
...,
native = FALSE,
s3 = FALSE,
s3credentials = NULL
)
file |
The file name (character) of the file in which the dataset is
be located. It is possible to provide an object of
class H5IdComponent representing a H5 location identifier
(file or group). See |
name |
The name of the dataset in the HDF5 file. |
index |
List of indices for subsetting. The length of the list has to agree with the dimensional extension of the HDF5 array. Each list element is an integer vector of indices. A list element equal to NULL chooses all indices in this dimension. Counting is R-style 1-based. |
start |
The start coordinate of a hyperslab (similar to subsetting in R). Counting is R-style 1-based. This argument is ignored, if index is not NULL. |
stride |
The stride of the hypercube. Read the introduction http://ftp.hdfgroup.org/HDF5/Tutor/phypecont.html before using this argument. R behaves like Fortran in this example. This argument is ignored, if index is not NULL. |
block |
The block size of the hyperslab. Read the introduction http://ftp.hdfgroup.org/HDF5/Tutor/phypecont.html before using this argument. R behaves like Fortran in this example. This argument is ignored, if index is not NULL. |
count |
The number of blocks to be read. This argument is ignored, if index is not NULL. |
compoundAsDataFrame |
If true, a compound datatype will be coerced to a data.frame. This is not possible, if the dataset is multi-dimensional. Otherwise the compound datatype will be returned as a list. Nested compound data types will be returned as a nested list. |
callGeneric |
If TRUE a generic function h5read.classname will be called if it exists depending on the dataset's class attribute within the HDF5 file. This function can be used to convert the standard output of h5read depending on the class attribute. Note that h5read is not a S3 generic function. Dispatching is done based on the HDF5 attribute after the standard h5read function. |
read.attributes |
(logical) If |
drop |
(logical) If TRUE, the HDF5 object is read as a vector with |
... |
Further arguments passed to |
native |
An object of class |
s3 |
Logical value indicating whether the file argument should be treated as a URL to an Amazon S3 bucket, rather than a local file path. |
s3credentials |
A list of length three, providing the credentials for accessing files in a private Amazon S3 bucket. |
Read an R object from an HDF5 file. If none of the arguments
start, stride, block, count
are specified, the dataset has the same
dimension in the HDF5 file and in memory. If the dataset already exists in
the HDF5 file, one can read subarrays, so called hyperslabs from
the HDF5 file. The arguments start, stride, block, count
define the
subset of the dataset in the HDF5 file that is to be read/written. See these
introductions to hyperslabs:
https://support.hdfgroup.org/HDF5/Tutor/selectsimple.html,
https://support.hdfgroup.org/HDF5/Tutor/select.html and
http://ftp.hdfgroup.org/HDF5/Tutor/phypecont.html. Please note that in
R the first dimension is the fastest changing dimension.
When viewing the HDF5 datasets with any C-program (e.g. HDFView), the order of dimensions is inverted. In the R interface counting starts with 1, whereas in the C-programs (e.g. HDFView) counting starts with 0.
Special cases. There are a few instances where rhdf5 will make assumptions
about the dataset you are reading and treat it slightly differently. 1)
complex numbers. If your datasets is a compound datatype, has only two
columns, and these are named 'r' and 'i' rhdf5 will assume the data is
intended to be complex numbers and will read this into R's complex type. If
that is not the case, you will need to extract the two values separately
using the Re()
and Im()
accessors manually.
h5read
returns an array with the data read.
Bernd Fischer, Mike Smith
h5ls
h5File <- tempfile(pattern = "ex_hdf5file.h5")
h5createFile(h5File)
# write a matrix
B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2))
h5write(B, h5File, "B")
# read a matrix
E = h5read(h5File,"B")
# write and read submatrix
h5createDataset(h5File, "S", c(5,8), storage.mode = "integer", chunk=c(5,1), level=7)
h5write(matrix(1:5,nr=5,nc=1), file=h5File, name="S", index=list(NULL,1))
h5read(h5File, "S")
h5read(h5File, "S", index=list(NULL,2:3))
# Read a subset of an hdf5 file in a public S3 bucket
h5read('https://rhdf5-public.s3.eu-central-1.amazonaws.com/rhdf5ex_t_float_3d.h5',
s3 = TRUE, name = "a1", index = list(NULL, 3, NULL))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.