Title: | R Interface to HDF5 |
---|---|
Description: | This package provides an interface between HDF5 and R. HDF5's main features are the ability to store and access very large and/or complex datasets and a wide variety of metadata on mass storage (disk) through a completely portable file format. The rhdf5 package is thus suited for the exchange of large and/or complex datasets between R and other software package, and for letting R applications work on datasets that are larger than the available RAM. |
Authors: | Bernd Fischer [aut], Mike Smith [aut, cre] , Gregoire Pau [aut], Martin Morgan [ctb], Daniel van Twisk [ctb] |
Maintainer: | Mike Smith <[email protected]> |
License: | Artistic-2.0 |
Version: | 2.51.1 |
Built: | 2024-12-10 03:15:07 UTC |
Source: | https://github.com/bioc/rhdf5 |
R function to create an HDF5 attribute and defining its dimensionality.
h5createAttribute( obj, attr, dims, maxdims = dims, file, storage.mode = "double", H5type = NULL, size = NULL, encoding = NULL, cset = NULL, native = FALSE )
h5createAttribute( obj, attr, dims, maxdims = dims, file, storage.mode = "double", H5type = NULL, size = NULL, encoding = NULL, cset = NULL, native = FALSE )
obj |
The name (character) of the object the attribute will be attatched
to. For advanced programmers it is possible to provide an object of class
H5IdComponent representing a H5 object identifier (file, group,
dataset). See |
attr |
Name of the attribute to be created. |
dims |
The dimensions of the attribute as a numeric vector. If
|
maxdims |
The maximum extension of the attribute. |
file |
The filename (character) of the file in which the dataset will be
located. For advanced programmers it is possible to provide an object of
class H5IdComponent representing an H5 location identifier. See
|
storage.mode |
The storage mode of the data to be written. Can be
obtained by |
H5type |
Advanced programmers can specify the datatype of the dataset
within the file. See |
size |
The maximum string length when If this argument is set to |
encoding |
The encoding of the string data type i.e. when |
cset |
Deprecated in favour of the |
native |
An object of class |
Creates a new attribute and attaches it to an existing HDF5 object. The function will fail, if the file doesn't exist or if there exists already another attribute with the same name for this object.
You can use h5writeAttribute()
immediately. It will create the attribute
for you.
Returns TRUE is attribute was created successfully and FALSE otherwise.
Bernd Fischer
https://portal.hdfgroup.org/display/HDF5
h5createFile()
, h5createGroup()
, h5createDataset()
,
h5read()
, h5write()
, rhdf5
h5File <- tempfile(pattern = "ex_createAttribute.h5") h5createFile(h5File) h5write(1:1, h5File, "A") fid <- H5Fopen(h5File) did <- H5Dopen(fid, "A") h5createAttribute (did, "time", c(1,10)) H5Dclose(did) H5Fclose(fid)
h5File <- tempfile(pattern = "ex_createAttribute.h5") h5createFile(h5File) h5write(1:1, h5File, "A") fid <- H5Fopen(h5File) did <- H5Dopen(fid, "A") h5createAttribute (did, "time", c(1,10)) H5Dclose(did) H5Fclose(fid)
R function to create an HDF5 dataset and defining its dimensionality and compression behaviour.
h5createDataset( file, dataset, dims, maxdims = dims, storage.mode = "double", H5type = NULL, size = NULL, encoding = NULL, chunk = dims, fillValue, level = 6, filter = "gzip", shuffle = TRUE, native = FALSE )
h5createDataset( file, dataset, dims, maxdims = dims, storage.mode = "double", H5type = NULL, size = NULL, encoding = NULL, chunk = dims, fillValue, level = 6, filter = "gzip", shuffle = TRUE, native = FALSE )
file |
The filename (character) of the file in which the dataset will be
located. For advanced programmers it is possible to provide an object of
class H5IdComponent representing a H5 location identifier (file or
group). See |
dataset |
Name of the dataset to be created. The name can contain group names, e.g. 'group/dataset', but the function will fail, if the group does not yet exist. |
dims |
The dimensions of the array as they will appear in the file. Note, the dimensions will appear in inverted order when viewing the file with a C-programm (e.g. HDFView), because the fastest changing dimension in R is the first one, whereas the fastest changing dimension in C is the last one. |
maxdims |
The maximum extension of the array. Use |
storage.mode |
The storage mode of the data to be written. Can be
obtained by |
H5type |
Advanced programmers can specify the datatype of the dataset
within the file. See |
size |
For |
encoding |
The encoding of the string data type. Valid options are "ASCII" or "UTF-8". |
chunk |
The chunk size used to store the dataset. It is an integer
vector of the same length as |
fillValue |
Standard value for filling the dataset. The storage.mode of value has to be convertible to the dataset type by HDF5. |
level |
The compression level used. An integer value between 0 (no compression) and 9 (highest and slowest compression). |
filter |
Character defining which compression filter should be applied to the chunks of the dataset. See the Details section for more information on the options that can be provided here. |
shuffle |
Logical defining whether the byte-shuffle algorithm should be applied to data prior to compression. |
native |
An object of class |
Creates a new dataset in an existing HDF5 file. The function will fail if the file doesn't exist or if there exists already another dataset with the same name within the specified file.
The size
argument is only used when storage.mode = 'character'
. When
storing strings HDF5 can use either a fixed or variable length datatype.
Setting size
to a positive integer will use fixed length strings where
size
defines the length. rhdf5 writes null padded strings by default
and so to avoid data loss the value provided here should be the length of the
longest string. Setting size = NULL
will use variable length strings. The
choice is probably dependent on the nature of the strings you're writing. The
principle difference is that a dataset of variable length strings will not be
compressed by HDF5 but each individual string only uses the space it
requires, whereas in a fixed length dataset each string is of length uses
size
, but the whole dataset can be compressed. This explored more in the
examples below.
The filter
argument can take several options matching to compression
filters distributed in either with the HDF5 library in Rhdf5lib or via
the rhdf5filters package. The plugins available and the corresponding
values for selecting them are shown below:
"GZIP"
,
"ZLIB"
,
"DEFLATE"
"SZIP"
"BZIP2"
"BLOSC_BLOSCLZ"
"BLOSC_LZ4"
"BLOSC_LZ4HC"
"BLOSC_SNAPPY"
"BLOSC_ZLIB"
"BLOSC_ZSTD"
"LZF"
"NONE"
Returns (invisibly) TRUE
if dataset was created successfully and FALSE
otherwise.
Bernd Fischer, Mike L. Smith
h5createFile()
, h5createGroup()
, h5read()
, h5write()
h5File <- tempfile(pattern = "_ex_createDataset.h5") h5createFile(h5File) # create dataset with compression h5createDataset(h5File, "A", c(5,8), storage.mode = "integer", chunk=c(5,1), level=6) # create dataset without compression h5createDataset(h5File, "B", c(5,8), storage.mode = "integer") h5createDataset(h5File, "C", c(5,8), storage.mode = "double") # create dataset with bzip2 compression h5createDataset(h5File, "D", c(5,8), storage.mode = "integer", chunk=c(5,1), filter = "BZIP2", level=6) # create a dataset of strings & define size based on longest string ex_strings <- c('long', 'longer', 'longest') h5createDataset(h5File, "E", storage.mode = "character", chunk = 3, level = 6, dims = length(ex_strings), size = max(nchar(ex_strings))) # write data to dataset h5write(matrix(1:40,nr=5,nc=8), file=h5File, name="A") # write second column h5write(matrix(1:5,nr=5,nc=1), file=h5File, name="B", index=list(NULL,2)) # write character vector h5write(ex_strings, file = h5File, name = "E") h5dump( h5File ) ## Investigating fixed vs variable length string datasets ## create 1000 random strings with length between 50 and 100 characters words <- ceiling(runif(n = 1000, min = 50, max = 100)) |> vapply(FUN = \(x) { paste(sample(letters, size = x, replace = TRUE), collapse = "") }, FUN.VALUE = character(1)) ## create two HDF5 files f1 <- tempfile() f2 <- tempfile() h5createFile(f1) h5createFile(f2) ## create two string datasets ## the first is variable length strings, the second fixed at the length of our longest word h5createDataset(f1, "strings", dims = length(words), storage.mode = "character", size = NULL, chunk = 25) h5createDataset(f2, "strings", dims = length(words), storage.mode = "character", size = max(nchar(words)), chunk = 25) ## Write the data h5write(words, f1, "strings") h5write(words, f2, "strings") ## Check file sizes. ## In this example the fixed length string dataset is normally much smaller file.size(f1) file.size(f2)
h5File <- tempfile(pattern = "_ex_createDataset.h5") h5createFile(h5File) # create dataset with compression h5createDataset(h5File, "A", c(5,8), storage.mode = "integer", chunk=c(5,1), level=6) # create dataset without compression h5createDataset(h5File, "B", c(5,8), storage.mode = "integer") h5createDataset(h5File, "C", c(5,8), storage.mode = "double") # create dataset with bzip2 compression h5createDataset(h5File, "D", c(5,8), storage.mode = "integer", chunk=c(5,1), filter = "BZIP2", level=6) # create a dataset of strings & define size based on longest string ex_strings <- c('long', 'longer', 'longest') h5createDataset(h5File, "E", storage.mode = "character", chunk = 3, level = 6, dims = length(ex_strings), size = max(nchar(ex_strings))) # write data to dataset h5write(matrix(1:40,nr=5,nc=8), file=h5File, name="A") # write second column h5write(matrix(1:5,nr=5,nc=1), file=h5File, name="B", index=list(NULL,2)) # write character vector h5write(ex_strings, file = h5File, name = "E") h5dump( h5File ) ## Investigating fixed vs variable length string datasets ## create 1000 random strings with length between 50 and 100 characters words <- ceiling(runif(n = 1000, min = 50, max = 100)) |> vapply(FUN = \(x) { paste(sample(letters, size = x, replace = TRUE), collapse = "") }, FUN.VALUE = character(1)) ## create two HDF5 files f1 <- tempfile() f2 <- tempfile() h5createFile(f1) h5createFile(f2) ## create two string datasets ## the first is variable length strings, the second fixed at the length of our longest word h5createDataset(f1, "strings", dims = length(words), storage.mode = "character", size = NULL, chunk = 25) h5createDataset(f2, "strings", dims = length(words), storage.mode = "character", size = max(nchar(words)), chunk = 25) ## Write the data h5write(words, f1, "strings") h5write(words, f2, "strings") ## Check file sizes. ## In this example the fixed length string dataset is normally much smaller file.size(f1) file.size(f2)
R function to create an empty HDF5 file.
h5createFile(file)
h5createFile(file)
file |
The filename of the HDF5 file. |
Creates an empty HDF5 file.
Returns (invisibly) TRUE
is file was created successfully and FALSE
otherwise.
Bernd Fischer
h5createGroup()
, h5createDataset()
,
h5read()
, h5write()
, rhdf5
h5File <- tempfile(pattern = "ex_createFile.h5") h5createFile(h5File) # create groups h5createGroup(h5File,"foo") h5createGroup(h5File,"foo/foobaa") h5ls(h5File)
h5File <- tempfile(pattern = "ex_createFile.h5") h5createFile(h5File) # create groups h5createGroup(h5File,"foo") h5createGroup(h5File,"foo/foobaa") h5ls(h5File)
Creates a group within an HDF5 file.
h5createGroup(file, group)
h5createGroup(file, group)
file |
The filename (character) of the file in which the dataset will
be located. For advanced programmers it is possible to provide an object of
class H5IdComponent representing a H5 location identifier
(file or group). See |
group |
The name of the new group. The name can contain a hierarchy of
groupnames, e.g. |
Creates a new group within an HDF5 file.
Returns TRUE is group was created successfully and FALSE otherwise.
Bernd Fischer
h5createFile()
, h5createDataset()
,
h5read()
, h5write()
h5File <- tempfile(pattern = "ex_createGroup.h5") h5createFile(h5File) # create groups h5createGroup(h5File, "foo") h5createGroup(h5File, "foo/foobaa") h5ls(h5File)
h5File <- tempfile(pattern = "ex_createGroup.h5") h5createFile(h5File) # create groups h5createGroup(h5File, "foo") h5createGroup(h5File, "foo/foobaa") h5ls(h5File)
Deletes the specified group or dataset from within an HDF5 file.
h5delete(file, name)
h5delete(file, name)
file |
The filename (character) of the file in which the object is located. |
name |
For |
Mike Smith
Deletes an attribute associated with a group or dataset within an HDF5 file.
h5deleteAttribute(file, name, attribute)
h5deleteAttribute(file, name, attribute)
file |
The filename (character) of the file in which the object is located. |
name |
The name of the object to which the attribute belongs. |
attribute |
Name of the attribute to be deleted. |
Mike Smith
Dump the content of an HDF5 file.
h5dump( file, recursive = TRUE, load = TRUE, all = FALSE, index_type = h5default("H5_INDEX"), order = h5default("H5_ITER"), s3 = FALSE, s3credentials = NULL, ..., native = FALSE )
h5dump( file, recursive = TRUE, load = TRUE, all = FALSE, index_type = h5default("H5_INDEX"), order = h5default("H5_ITER"), s3 = FALSE, s3credentials = NULL, ..., native = FALSE )
file |
The filename (character) of the file in which the dataset will
be located. You can also provide an object of class H5IdComponent
representing a H5 location identifier (file or group). See |
recursive |
If |
load |
If |
all |
If |
index_type |
See |
order |
See |
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. |
... |
Arguments passed to |
native |
An object of class |
Returns a hierarchical list structure representing the HDF5
group hierarchy. It either returns the datasets within the list structure
(load=TRUE
) or it returns a data.frame
for each dataset with the
dataset header information (load=FALSE
).
Bernd Fischer, Mike L. Smith
h5File <- tempfile(pattern = "ex_dump.h5") h5createFile(h5File) # create groups h5createGroup(h5File,"foo") h5createGroup(h5File,"foo/foobaa") # write a matrix B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) attr(B, "scale") <- "liter" h5write(B, h5File,"foo/B") # list content of hdf5 file h5dump(h5File) # list content of an hdf5 file in a public S3 bucket h5dump(file = "https://rhdf5-public.s3.eu-central-1.amazonaws.com/h5ex_t_array.h5", s3 = TRUE)
h5File <- tempfile(pattern = "ex_dump.h5") h5createFile(h5File) # create groups h5createGroup(h5File,"foo") h5createGroup(h5File,"foo/foobaa") # write a matrix B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) attr(B, "scale") <- "liter" h5write(B, h5File,"foo/B") # list content of hdf5 file h5dump(h5File) # list content of an hdf5 file in a public S3 bucket h5dump(file = "https://rhdf5-public.s3.eu-central-1.amazonaws.com/h5ex_t_array.h5", s3 = TRUE)
Sets the options for handling HDF5 error messages in the R sessions.
h5errorHandling(type = "normal")
h5errorHandling(type = "normal")
type |
'normal' (default) shows a one line error message in R. 'verbose' shows the whole HDF5 error message. 'suppress' suppresses the HDF5 error messages completely. |
Returns 0 if options are set successfully.
Bernd Fischer
h5errorHandling("normal")
h5errorHandling("normal")
HDF5 1.10 uses file locking by default. On some file systems this is not available, and the HDF5 library will throw an error if the user attempts to create or access a file located on such a file system. These functions help identify if file locking is available without throwing an error, and allow the locking to be disabled for the duration of the R session if needed.
h5testFileLocking(location) h5disableFileLocking() h5enableFileLocking()
h5testFileLocking(location) h5disableFileLocking() h5enableFileLocking()
location |
The name of a directory or file to test. If an existing directory is provided a temporary file will be created in this folder. If non-existant location is provided a file with the name will be created, tested for file locking, and then removed. Providing an existing file will result in an error. |
h5testFileLocking
will create a temporary file and then attempt to
apply a file lock using the appropriate function within the HDF5 library.
The success or failure of the locking is then recorded and the temporary
file removed. Even relatively low level functions such as
H5Fcreate
will fail inelegantly if file locking fails.
h5disableFileLocking
will set the environment variable
RHDF5_USE_FILE_LOCKING=FALSE
, which is the recommended was to disable
this behaviour if file locking is not supported. This will only persist
within the current R session. You can set the environment variable outside
of R if this is a more general issue on your system.
h5enableFileLocking
will unset the RHDF5_USE_FILE_LOCKING
environment variable.
More discussion of HDF5's use of file locking can be found online e.g. https://forum.hdfgroup.org/t/hdf5-1-10-0-and-flock/3761/4 or https://forum.hdfgroup.org/t/hdf5-files-on-nfs/3985/5
h5testFileLocking
returns TRUE
if a file can be
successfully locked at the specified location, or FALSE
otherwise.
h5disableFileLocking
and h5enableFileLocking
set are called
for the side effect of setting or unsetting the environment variable
HDF5_USE_FILE_LOCKING
and do not return anything.
Mike Smith
## either a file name or directory can be tested file <- tempfile() dir <- tempdir() h5testFileLocking(dir) h5testFileLocking(file) ## we can check for file locking, and disable if needed if( !h5testFileLocking(dir) ) { h5disableFileLocking() }
## either a file name or directory can be tested file <- tempfile() dir <- tempdir() h5testFileLocking(dir) h5testFileLocking(file) ## we can check for file locking, and disable if needed if( !h5testFileLocking(dir) ) { h5disableFileLocking() }
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 )
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
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))
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))
Read all attributes from a given location in an HDF5 file
h5readAttributes(file, name, native = FALSE, ...)
h5readAttributes(file, name, native = FALSE, ...)
file |
Character vector of length 1, giving the path to the HDF5 |
name |
Path within the HDF5 file to the object whose attributes should be read. |
native |
An object of class |
... |
Further arguments passed to |
A named list of the same length as the number of attributes attached to the specific object. The names of the list entries correspond to the attribute names. If no attributes are found an empty list is returned.
Saves a number of R objects to an HDF5 file.
h5save(..., file, name = NULL, createnewfile = TRUE, native = FALSE)
h5save(..., file, name = NULL, createnewfile = TRUE, native = FALSE)
... |
The objects to be saved. |
file |
The filename (character) of the file in which the dataset will
be located. It is also possible to provide an object of
class H5IdComponent representing a H5 location identifier
(file or group). See |
name |
A character vector of names for the datasets. The length of the name vector should match the number of objects. |
createnewfile |
If |
native |
An object of class |
The objects will be saved to the HDF5 file. If the file does not exists it
will be created. The data can be read again by either h5dump()
or individually for each dataset by h5read()
.
Nothing returned.
Bernd Fischer
A = 1:7; B = 1:18; D = seq(0,1,by=0.1) h5File <- tempfile(pattern = "ex_save.h5") h5save(A, B, D, file = h5File) h5dump(h5File)
A = 1:7; B = 1:18; D = seq(0,1,by=0.1) h5File <- tempfile(pattern = "ex_save.h5") h5save(A, B, D, file = h5File) h5dump(h5File)
Set a new dataset extension to an existing dataset in an HDF5 file
h5set_extent(file, dataset, dims, native = FALSE)
h5set_extent(file, dataset, dims, native = FALSE)
file |
The filename (character) of the file in which the dataset will
be located. For advanced programmers it is possible to provide an object of
class H5IdComponent representing a H5 location identifier
(file or group). See |
dataset |
The name of the dataset in the HDF5 file, or an object of
class H5IdComponent representing a H5 dataset identifier. See
|
dims |
The dimensions of the array as they will appear in the file. Note, the dimensions will appear in inverted order when viewing the file with a C program (e.g. HDFView), because the fastest changing dimension in R is the first one, whereas the fastest changing dimension in C is the last one. |
native |
An object of class |
Returns TRUE
if the dimension of the dataset was changed successfully
and FALSE
otherwise.
Bernd Fischer, Mike Smith
tmpfile <- tempfile() h5createFile(file=tmpfile) h5createDataset(tmpfile, "A", c(10,12), c(20,24)) h5ls(tmpfile, all=TRUE)[c("dim", "maxdim")] h5set_extent(tmpfile, "A", c(20,24)) h5ls(tmpfile, all=TRUE)[c("dim", "maxdim")]
tmpfile <- tempfile() h5createFile(file=tmpfile) h5createDataset(tmpfile, "A", c(10,12), c(20,24)) h5ls(tmpfile, all=TRUE)[c("dim", "maxdim")] h5set_extent(tmpfile, "A", c(20,24)) h5ls(tmpfile, all=TRUE)[c("dim", "maxdim")]
Writes an R object to an HDF5 file. This function can be used to write either full arrays/vectors or subarrays (hyperslabs) within an existing dataset.
h5write(obj, file, name, ...) ## Default S3 method: h5write( obj, file, name, createnewfile = TRUE, write.attributes = FALSE, ..., native = FALSE ) h5writeDataset(obj, h5loc, name, ...) ## S3 method for class 'data.frame' h5writeDataset(obj, h5loc, name, level = 6, chunk, DataFrameAsCompound = TRUE) ## S3 method for class 'array' h5writeDataset( obj, h5loc, name, index = NULL, start = NULL, stride = NULL, block = NULL, count = NULL, size = NULL, variableLengthString = FALSE, encoding = NULL, level = 6 )
h5write(obj, file, name, ...) ## Default S3 method: h5write( obj, file, name, createnewfile = TRUE, write.attributes = FALSE, ..., native = FALSE ) h5writeDataset(obj, h5loc, name, ...) ## S3 method for class 'data.frame' h5writeDataset(obj, h5loc, name, level = 6, chunk, DataFrameAsCompound = TRUE) ## S3 method for class 'array' h5writeDataset( obj, h5loc, name, index = NULL, start = NULL, stride = NULL, block = NULL, count = NULL, size = NULL, variableLengthString = FALSE, encoding = NULL, level = 6 )
obj |
The R object to be written. |
file |
The filename (character) of the file in which the dataset will be
located. For advanced programmers 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. |
... |
Further arguments passed to |
createnewfile |
If |
write.attributes |
(logical) If TRUE, all R-attributes attached to the
object |
native |
An object of class |
h5loc |
An object of class H5IdComponent representing a H5
location identifier (file or group). See |
level |
The compression level. An integer value between 0 (no
compression) and 9 (highest and slowest compression). Only used, if the
dataset does not yet exist. See |
chunk |
Specifies the number of items to be include in an HDF5 chunk. If
left unspecified the defaults is the smaller of: the total number of
elements or the number of elements that fit within 4GB of memory. If
|
DataFrameAsCompound |
If true, a |
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 |
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 written. This argument is ignored, if index is not NULL. |
size |
The length of the fixed-width string data type, when |
variableLengthString |
Whether character vectors should be written as
variable-length strings into the attributes. If |
encoding |
The encoding of the string data type. Valid options are "ASCII" or "UTF-8". |
Writes an R object to an HDF5 file. If none of the arguments start,
stride, block, count
is 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 write subarrays, (so called hyperslabs) to the HDF5 file. The arguments
start, stride, block, count
define the subset of the dataset in the
HDF5 file that is to be written to. 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.
If code obj
is of type 'complex' then it will be written as a compound
datatype to the HDF5, with elements named 'r' and 'i' for the real and
imaginary parts respectively.
h5write
returns 0 if successful.
Bernd Fischer, Mike Smith
https://portal.hdfgroup.org/display/HDF5
h5ls
, h5createFile
,
h5createDataset
, rhdf5
h5File <- tempfile(fileext = ".h5") h5createFile( h5File ) # write a matrix B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) attr(B, "scale") <- "liter" h5write(B, h5File,"B") # write a 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))
h5File <- tempfile(fileext = ".h5") h5createFile( h5File ) # write a matrix B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) attr(B, "scale") <- "liter" h5write(B, h5File,"B") # write a 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))
Write an R object as an HDF5 attribute
h5writeAttribute( attr, h5obj, name, h5loc, encoding = NULL, variableLengthString = FALSE, asScalar = FALSE, checkForNA = TRUE ) ## S3 method for class 'array' h5writeAttribute( attr, h5obj, name, h5loc, encoding = NULL, variableLengthString = FALSE, asScalar = FALSE, checkForNA = TRUE )
h5writeAttribute( attr, h5obj, name, h5loc, encoding = NULL, variableLengthString = FALSE, asScalar = FALSE, checkForNA = TRUE ) ## S3 method for class 'array' h5writeAttribute( attr, h5obj, name, h5loc, encoding = NULL, variableLengthString = FALSE, asScalar = FALSE, checkForNA = TRUE )
attr |
The R object to be written as an HDF5 attribute. |
h5obj |
Normally an object of class H5IdComponent representing a
H5 object identifier (file, group, or dataset). See
|
name |
The name of the attribute to be written. |
h5loc |
The location of the group or dataset within a file to which the
attribute should be attached. This argument is only used if the
|
encoding |
The encoding of the string data type. Valid options are "ASCII" and "UTF-8". |
variableLengthString |
Whether character vectors should be written as variable-length strings into the attributes. |
asScalar |
Whether length-1 |
checkForNA |
Whether a |
Close an HDF5 attribute
H5Aclose(h5attribute)
H5Aclose(h5attribute)
h5attribute |
An object of class H5IdComponent representing a
the attribute to be closed. Normally created by |
Creates an attribute, name
, which is attached to the object specified
by the identifier h5obj
. The attribute name must be unique for the object.
H5Acreate(h5obj, name, dtype_id, h5space)
H5Acreate(h5obj, name, dtype_id, h5space)
h5obj |
An object of class H5IdComponent representing a H5 object
identifier (file, group, or dataset). See |
name |
The name of the attribute (character). |
dtype_id |
A character name of a datatype. See |
h5space |
An object of class H5IdComponent representing a H5
dataspace. See |
An object of class H5IdComponent representing a H5 attribute identifier.
Delete an specified attribute of an HDF5 object
H5Adelete(h5obj, name)
H5Adelete(h5obj, name)
h5obj |
An object of class H5IdComponent representing a H5 object
identifier (file, group, or dataset). See |
name |
The name of the attribute (character). |
Check whether an specific attribute exists for an HDF5 object
H5Aexists(h5obj, name)
H5Aexists(h5obj, name)
h5obj |
An object of class H5IdComponent representing a H5 object
identifier (file, group, or dataset). See |
name |
The name of the attribute (character). |
Retrieves the name of the attribute specified by an HDF5 attribute object.
H5Aget_name(h5attribute)
H5Aget_name(h5attribute)
h5attribute |
An object of class H5IdComponent representing an
attribute. Normally created by |
A character vector of length 1 containing the name of the attribute.
Get a copy of the attribute dataspace
H5Aget_space(h5attribute)
H5Aget_space(h5attribute)
h5attribute |
An object of class H5IdComponent representing an
attribute. Normally created by |
Returns an object of class H5IdComponent representing a H5 dataspace identifier
Get a copy of the attribute datatype
H5Aget_type(h5attribute)
H5Aget_type(h5attribute)
h5attribute |
An object of class H5IdComponent representing an
attribute. Normally created by |
Open an attribute for an HDF5 object
H5Aopen(h5obj, name) H5Aopen_by_name(h5obj, objname = ".", name) H5Aopen_by_idx( h5obj, n, objname = ".", index_type = h5default("H5_INDEX"), order = h5default("H5_ITER") )
H5Aopen(h5obj, name) H5Aopen_by_name(h5obj, objname = ".", name) H5Aopen_by_idx( h5obj, n, objname = ".", index_type = h5default("H5_INDEX"), order = h5default("H5_ITER") )
h5obj |
An object of class H5IdComponent representing a H5 object
identifier (file, group, or dataset). See |
name |
The name of the attribute (character). |
objname |
The name of the object the attribute belongs to. |
n |
Opens attribute number |
index_type |
See |
order |
See |
An object of class H5IdComponent representing a H5 attribute identifier.
Read data from an HDF5 attribute
H5Aread(h5attribute, buf = NULL, bit64conversion)
H5Aread(h5attribute, buf = NULL, bit64conversion)
h5attribute |
An object of class H5IdComponent representing an
attribute. Normally created by |
buf |
Optional buffer to store retrieved values. The buffer size has to
fit the size of the memory space |
bit64conversion |
Defines how 64-bit integers are converted. (See the details section for more information on these options.) |
Internally, R does not support 64-bit integers. All integers in R are 32-bit integers. By setting bit64conversion='int', a coercing to 32-bit integers is enforced, with the risk of data loss, but with the insurance that numbers are represented as integers. bit64conversion='double' coerces the 64-bit integers to floating point numbers. doubles can represent integers with up to 54-bits, but they are not represented as integer values anymore. For larger numbers there is again a data loss. bit64conversion='bit64' is recommended way of coercing. It represents the 64-bit integers as objects of class 'integer64' as defined in the package 'bit64'. Make sure that you have installed 'bit64'. The datatype 'integer64' is not part of base R, but defined in an external package. This can produce unexpected behaviour when working with the data.
If buf=NULL
returns the contents of the attribute. Otherwise
return 0 if attribute is read successfully.
Write data to an HDF5 attribute
H5Awrite(h5attribute, buf)
H5Awrite(h5attribute, buf)
h5attribute |
An object of class H5IdComponent representing an
attribute. Normally created by |
buf |
The data to be written. |
This functions can be used in two ways. Firstly, it can be passed one or
more H5IdComponent objects and it'll will try to close all of them
regardless of the whether they represent a file, group, dataset etc. This
can be easier than making multiple calls to H5Fclose()
, H5Gclose()
, etc.
h5closeAll(...)
h5closeAll(...)
... |
One or more objects of class H5IdComponent which should be closed. If nothing is provided to the function, all open handles will be closed. |
Secondly, cccasionally references to HDF5 files, groups, datasets etc can be created and not closed correctly. Maybe because a function stopped before getting to the close statement, or the open handle was not assigned to an R variable. If no arguments are provide this function identifies all open handles and closes them.
Doesn't return anything. Called for the side-effect of closing open HDF5 handles.
Mike Smith
## create an empty file and then re-open it h5File <- tempfile(pattern = "ex_h5closeAll.h5") h5createFile(h5File) H5Fopen(h5File) ## list all open identifiers h5listIdentifier() ## close all open identifiers and verify h5closeAll() h5listIdentifier()
## create an empty file and then re-open it h5File <- tempfile(pattern = "ex_h5closeAll.h5") h5createFile(h5File) H5Fopen(h5File) ## list all open identifiers h5listIdentifier() ## close all open identifiers and verify h5closeAll() h5listIdentifier()
Access to HDF5 constants.
h5const(type = "") h5constType() h5default(type = "")
h5const(type = "") h5constType() h5default(type = "")
type |
A character name of a group of constants. |
These functions provide a list of HDF5 constants that are defined in the R
package. h5constType
provides a list of group names and
h5const
gives the constants defined within a group. h5default
gives the default choice for each group.
A character vector with names of HDF5 constants or groups.
Bernd Fischer
h5constType()[1] h5const(h5constType()[1])
h5constType()[1] h5const(h5constType()[1])
Additional functions for finding details of dataset chunking.
H5Dchunk_dims(h5dataset) H5Dis_chunked(h5dataset)
H5Dchunk_dims(h5dataset) H5Dis_chunked(h5dataset)
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset. |
These functions do not map directly to the HDF5 C API but follow the same style and are included as potentially useful additions.
H5Dis_chunked
tests whether a dataset is chunked.
H5Dchunk_dims
will return the dimensions of the dataset chunks.
H5Dchunk_dims
: If the supplied dataset is chunked returns a vector, with length
equal to the rank of the dataset, containing the size of the dataset
dimensions. Returns NULL
if the given dataset is not chunked.
H5Dis_chunked
: returns TRUE
if a dataset is chunked and FALSE
otherwise.
Mike Smith
Close an open HDF5 dataset
H5Dclose(h5dataset)
H5Dclose(h5dataset)
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset |
Create a new HDF5 dataset
H5Dcreate( h5loc, name, dtype_id, h5space, lcpl = NULL, dcpl = NULL, dapl = NULL )
H5Dcreate( h5loc, name, dtype_id, h5space, lcpl = NULL, dcpl = NULL, dapl = NULL )
h5loc |
An object of class H5IdComponent representing a H5
location identifier (file or group). See |
name |
Name of the dataset. |
dtype_id |
A character name of a datatype. See |
h5space |
An object of class H5IdComponent representing a H5 dataspace.
See |
lcpl , dcpl , dapl
|
An objects of class H5IdComponent representing HDF5 property lists. Specially these should respectively be: a link creation property list, a dataset creation property list, a dataset access property list |
An object of class H5IdComponent
representing the opened dataset.
Return a copy of the dataset creation property list for a dataset
H5Dget_create_plist(h5dataset)
H5Dget_create_plist(h5dataset)
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset |
Return a copy of the HDF5 dataspace for a dataset
H5Dget_space(h5dataset)
H5Dget_space(h5dataset)
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset |
Returns an object of class H5IdComponent
representing a HDF5
dataspace identifier
H5Dget_storage_size
returns the amount of storage, in bytes, allocated in
an HDF5 file to hold a given dataset. This is the amount of space required
on-disk, which not typically a good indicator of the amount of memory
that will be required to read the complete dataset.
H5Dget_storage_size(h5dataset)
H5Dget_storage_size(h5dataset)
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset |
Returns an integer giving the number of bytes allocated in the file to the dataset.
Return a copy of the HDF5 datatype for a dataset
H5Dget_type(h5dataset)
H5Dget_type(h5dataset)
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset |
Open an existing HDF5 dataset
H5Dopen(h5loc, name, dapl = NULL)
H5Dopen(h5loc, name, dapl = NULL)
h5loc |
An object of class H5IdComponent representing a H5 location identifier (file or group). |
name |
Name of the dataset to open. |
dapl |
An object of class H5IdComponent representing a H5 dataset access property list. |
An object of class H5IdComponent
representing the opened dataset.
To prevent memory leaks this must be closed with a call to H5Dclose()
when no longer needed.
h5file <- tempfile(fileext = ".h5") h5createFile( h5file ) h5createDataset( h5file, dataset = "A", dims = 10) fid <- H5Fopen( h5file ) did <- H5Dopen( h5loc = fid, name = "A") did ## rember to close open handles H5Dclose( did ) H5Fclose( fid )
h5file <- tempfile(fileext = ".h5") h5createFile( h5file ) h5createDataset( h5file, dataset = "A", dims = 10) fid <- H5Fopen( h5file ) did <- H5Dopen( h5loc = fid, name = "A") did ## rember to close open handles H5Dclose( did ) H5Fclose( fid )
H5Dread()
reads a (partial) dataset from an HDF5 file into the R session.
H5Dread( h5dataset, h5spaceFile = NULL, h5spaceMem = NULL, buf = NULL, compoundAsDataFrame = TRUE, bit64conversion, drop = FALSE )
H5Dread( h5dataset, h5spaceFile = NULL, h5spaceMem = NULL, buf = NULL, compoundAsDataFrame = TRUE, bit64conversion, drop = FALSE )
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset. |
h5spaceFile |
An object of class |
h5spaceMem |
An object of class |
buf |
Buffer to hold the read data. The buffer size has to fit the
size of the memory space |
compoundAsDataFrame |
Logical vector of length 1. If |
bit64conversion |
Defines how 64-bit integers are converted. (See the details section for more information on these options.) |
drop |
Logical vector of length 1. If |
Internally, R does not support 64-bit integers. All integers in R are 32-bit integers. By setting bit64conversion='int', a coercing to 32-bit integers is enforced, with the risk of data loss, but with the insurance that numbers are represented as integers. bit64conversion='double' coerces the 64-bit integers to floating point numbers. doubles can represent integers with up to 54-bits, but they are not represented as integer values anymore. For larger numbers there is again a data loss. bit64conversion='bit64' is recommended way of coercing. It represents the 64-bit integers as objects of class 'integer64' as defined in the package 'bit64'. Make sure that you have installed 'bit64'. The datatype 'integer64' is not part of base R, but defined in an external package. This can produce unexpected behaviour when working with the data.
Change the dimensions of an HDF5 dataset
H5Dset_extent(h5dataset, size)
H5Dset_extent(h5dataset, size)
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset. |
size |
An integer vector with the new dimension of the dataset. |
This function can only be applied to datasets that meet the following criteria:
A chunked dataset with unlimited dimensions
A chunked dataset with fixed dimensions if the new dimension sizes are less than the maximum sizes set with maxdims
A logical vector of length 1. Value will be TRUE
if the operation
was sucessful and FALSE
otherwise.
Bernd Fischer, Mike Smith
Write data to dataset
H5Dwrite(h5dataset, buf, h5type = NULL, h5spaceMem = NULL, h5spaceFile = NULL)
H5Dwrite(h5dataset, buf, h5type = NULL, h5spaceMem = NULL, h5spaceFile = NULL)
h5dataset |
Object of class H5IdComponent representing an open HDF5 dataset. |
buf |
The R object containing the data to be written to the dataset. |
h5type |
Datatype of the HDF5 dataset to be written. If left as |
h5spaceMem , h5spaceFile
|
H5IdComponent objects representing the
memory and file dataspaces respectively. If these are left |
Close access to an HDF5 file
H5Fclose(h5file)
H5Fclose(h5file)
h5file |
H5IdComponent representing an HDF5 file ID. Typically
created via |
Create an HDF5 file
H5Fcreate( name, flags = h5default("H5F_ACC"), fcpl = NULL, fapl = NULL, native = FALSE )
H5Fcreate( name, flags = h5default("H5F_ACC"), fcpl = NULL, fapl = NULL, native = FALSE )
name |
The name of the HDF5 file to create. |
flags |
See |
fcpl , fapl
|
Object object of class H5IdComponent. This should
representing a file creation property list and a file access property list
respectively. See |
native |
An object of class |
Flush all buffers associated with a file to disk
H5Fflush(h5file, scope = h5default("H5F_SCOPE"))
H5Fflush(h5file, scope = h5default("H5F_SCOPE"))
h5file |
H5IdComponent representing any object associated with the file to be flushed. |
scope |
Specifies whether the scope of the flushing action is global
(flushes the entire virtual file) or local (flushes only the specified
file). Valid values are |
H5Fget_filesize()
returns the size in bytes of the HDF5 file specified by
h5file
.
H5Fget_filesize(h5file)
H5Fget_filesize(h5file)
h5file |
H5IdComponent representing an HDF5 file ID. Typically
created via |
Retrieve the name of the file to which an object belongs
H5Fget_name(h5obj)
H5Fget_name(h5obj)
h5obj |
An object of class H5IdComponent. Despite this being an H5F function, it works equally well on H5 file, group, dataset and attribute datatypes. |
## use an example file and show its location h5file <- system.file("testfiles", "h5ex_t_array.h5", package = "rhdf5") h5file ## open a file handle and confirm we can identify the file it points to fid <- H5Fopen(h5file) H5Fget_name(fid) ## H5Fget_name() can be applied to group and dataset handles too gid <- H5Gopen(fid, name = "/") did <- H5Dopen(fid, name = "DS1") H5Fget_name(gid) H5Fget_name(did) ## tidy up H5Dclose(did) H5Gclose(gid) H5Fclose(fid)
## use an example file and show its location h5file <- system.file("testfiles", "h5ex_t_array.h5", package = "rhdf5") h5file ## open a file handle and confirm we can identify the file it points to fid <- H5Fopen(h5file) H5Fget_name(fid) ## H5Fget_name() can be applied to group and dataset handles too gid <- H5Gopen(fid, name = "/") did <- H5Dopen(fid, name = "DS1") H5Fget_name(gid) H5Fget_name(did) ## tidy up H5Dclose(did) H5Gclose(gid) H5Fclose(fid)
Get property lists associated with an HDF5 file
H5Fget_create_plist(h5file) H5Fget_access_plist(h5file)
H5Fget_create_plist(h5file) H5Fget_access_plist(h5file)
h5file |
An object of class H5IdComponent representing a H5
file identifier. Typically produced by |
H5Fis_hdf5()
determines whether a file is in the HDF5 format.
H5Fis_hdf5(name, showWarnings = TRUE)
H5Fis_hdf5(name, showWarnings = TRUE)
name |
Character vector of length 1, giving the path to the file to be checked. |
showWarnings |
If the file doesn't exist an warning is generated.
Setting this argument to |
Returns TRUE
, if the file is an HDF5 file, or FALSE
otherwise.
In the case the file doesn't exist, NA
is returned
Open an existing HDF5 file
H5Fopen(name, flags = h5default("H5F_ACC_RD"), fapl = NULL, native = FALSE)
H5Fopen(name, flags = h5default("H5F_ACC_RD"), fapl = NULL, native = FALSE)
name |
The name (or path) of the HDF5 file to be opened. |
flags |
Character string defining the access mode for opening the file. |
fapl |
H5IdComponent object representing a file access property list.
Leaving this argument as |
native |
An object of class |
Possible values for the flags
argument are H5F_ACC_RDWR
and H5F_ACC_RDONLY
.
Note that HDF5's "Single Write Multiple Reader (SWMR) mode is not currently supported via
rhdf5.
These low level functions provide general library functions for HDF5.
H5open() H5close() H5garbage_collect() H5get_libversion()
H5open() H5close() H5garbage_collect() H5get_libversion()
H5open
initializes the HDF5 library.
H5close
flushes all data to disk, closes all open identifiers, and cleans up memory.
H5garbage_collect
cleans up memory.
H5get_libversion
returns the version number of the HDF5 C-library.
Bernd Fischer, Mike Smith
## Not run: H5open() H5close() H5garbage_collect() H5get_libversion() ## End(Not run)
## Not run: H5open() H5close() H5garbage_collect() H5get_libversion() ## End(Not run)
Close a specified group
H5Gclose(h5group)
H5Gclose(h5group)
h5group |
An object of class H5IdComponent representing a H5
group. Typically created via |
H5Gcreate
is used to a new group and link it into a file.
H5Gcreate(h5loc, name)
H5Gcreate(h5loc, name)
h5loc |
An object of class H5IdComponent |
name |
Name of the new group to be created. |
Create a new HDF5 group without linking it into a file
H5Gcreate_anon(h5loc)
H5Gcreate_anon(h5loc)
h5loc |
An object of class H5IdComponent specifying the file in which the new group is to be created. |
H5Gcreate_anon
returns an object of class H5IdComponent
representing the newly created group. However at this point is is still
anonymous, and must be linked into the file structure via H5Olink()
.
If this is not done, the group will be deleted from the file when it
is closed.
Retrieve information about a group
H5Gget_info(h5loc) H5Gget_info_by_name(h5loc, group_name) H5Gget_info_by_idx( h5loc, n, group_name = ".", index_type = h5default("H5_INDEX"), order = h5default("H5_ITER") )
H5Gget_info(h5loc) H5Gget_info_by_name(h5loc, group_name) H5Gget_info_by_idx( h5loc, n, group_name = ".", index_type = h5default("H5_INDEX"), order = h5default("H5_ITER") )
h5loc |
An object of class H5IdComponent representing a H5 group. |
group_name |
An additional group name specifying the group for which
information is sought. It is interpreted relative to |
n |
Position in the index of the group for which information is retrieved. |
index_type |
See |
order |
See |
A list with group information
h5file <- system.file("testfiles", "multiple_dtypes.h5", package="rhdf5") fid <- H5Fopen(h5file) gid <- H5Gopen(fid, "/foo") gid H5Gget_info(gid) H5Gclose(gid) ## the "get_info_by" functions take the H5 object that contains the ## group(s) of interest. We can retrieve information by index or by name H5Gget_info_by_idx(fid, 3) H5Gget_info_by_name(fid,"/foo") H5Fclose(fid)
h5file <- system.file("testfiles", "multiple_dtypes.h5", package="rhdf5") fid <- H5Fopen(h5file) gid <- H5Gopen(fid, "/foo") gid H5Gget_info(gid) H5Gclose(gid) ## the "get_info_by" functions take the H5 object that contains the ## group(s) of interest. We can retrieve information by index or by name H5Gget_info_by_idx(fid, 3) H5Gget_info_by_name(fid,"/foo") H5Fclose(fid)
Open a specified group
H5Gopen(h5loc, name)
H5Gopen(h5loc, name)
h5loc |
An object of class H5IdComponent representing a H5 file or group that contains the group to be opened. |
name |
Name of the group to open. |
An object of class H5IdComponent representing the opened
group. When access to the group is no longer needed this should be released
with H5Gclose()
to prevent resource leakage.
A class representing a HDF5 identifier handle. HDF5 identifiers represent open files, groups, datasets, dataspaces, attributes, and datatypes.
## S4 method for signature 'H5IdComponent' show(object) ## S4 method for signature 'H5IdComponent,character' e1 & e2 ## S4 method for signature 'H5IdComponent' x$name ## S4 replacement method for signature 'H5IdComponent' x$name <- value ## S4 method for signature 'H5IdComponent' x[i, j, ..., drop = TRUE] ## S4 replacement method for signature 'H5IdComponent' x[i, j, ...] <- value
## S4 method for signature 'H5IdComponent' show(object) ## S4 method for signature 'H5IdComponent,character' e1 & e2 ## S4 method for signature 'H5IdComponent' x$name ## S4 replacement method for signature 'H5IdComponent' x$name <- value ## S4 method for signature 'H5IdComponent' x[i, j, ..., drop = TRUE] ## S4 replacement method for signature 'H5IdComponent' x[i, j, ...] <- value
object |
Object of class |
e1 |
An |
e2 |
Character giving the path to an HDF5 group or dataset relative to |
x |
Object of class |
name |
Character giving the path to an HDF5 group or dataset relative to |
value |
Array-like R object containing value to be inserted into the HDF5 dataset. |
i , j , ...
|
Indices specifying elements to extract or replace. Indices
are |
drop |
If |
show(H5IdComponent)
: Print details of the object to screen.
e1 & e2
: Returns a group handle or dataset handle for the
group or dataset name
in the HDF5 location h5loc
. h5loc
can either be a file handle
as returned by H5Fopen or a group handle as e.g. returned by h5f$g1
or
h5f$'/g1/g2'
.
$
: Reads the HDF5 object name
in the HDF5 location x
. x
can either be
a file handle as returned by H5Fopen or a group handle as e.g. returned by
h5f$g1
or h5f$'/g1/g2'
.
`$`(H5IdComponent) <- value
: Writes the assigned object to to the HDF5 file at
location e1. e1 can either be a file handle as returned by H5Fopen or a
group handle as e.g. returned by h5f$g1 or h5f$'/g1/g2's. The storage.mode
of the assigned object has to be compatible to the datatype of the HDF5
dataset. The dimension of the assigned object have to be identical the
dimensions of the HDF5 dataset. To create a new HDF5 dataset with specific
properties (e.g. compression level or chunk size), please use the function
h5createDataset first.
[
: Subsetting of an HDF5 dataset. The function reads a
subset of an HDF5 dataset. The given dimensions have to fit the dimensions
of the HDF5 dataset.
`[`(H5IdComponent) <- value
: Subsetting of an HDF5 dataset. The function writes
an R data object to a subset of an HDF5 dataset. The given dimensions have
to fit the dimensions of the HDF5 dataset. The HDF5 dataset has to be
created beforehand, e.g. by h5createDataset.
ID
integer
of length 1. Contains the handle of C-type hid_t
.
native
An object of class logical
. If TRUE, array-like objects
are treated as stored in HDF5 row-major rather than R column-major
orientation. Using native = TRUE
increases HDF5 file portability
between programming languages. A file written with native = TRUE
should also be read with native = TRUE
Retrieve the name of an object from a given identifier
H5Iget_name(h5obj)
H5Iget_name(h5obj)
h5obj |
An object of class H5IdComponent. Can represent a file, group, dataset or attribute. |
Possible types returned by the function are:
H5I_FILE
H5I_GROUP
H5I_DATATYPE
H5I_DATASPACE
H5I_DATASET
H5I_ATTR
H5Iget_type(h5identifier)
H5Iget_type(h5identifier)
h5identifier |
Object of class H5IdComponent. |
Returns a character vector of length 1 containing the HDF5 type for the supplied identifier.
h5file <- system.file("testfiles", "h5ex_t_array.h5", package="rhdf5") fid <- H5Fopen(h5file) gid <- H5Gopen(fid, "/") ## identify the HDF5 types for these identifiers H5Iget_type(fid) H5Iget_type(gid) ## tidy up H5Gclose(gid) H5Fclose(fid)
h5file <- system.file("testfiles", "h5ex_t_array.h5", package="rhdf5") fid <- H5Fopen(h5file) gid <- H5Gopen(fid, "/") ## identify the HDF5 types for these identifiers H5Iget_type(fid) H5Iget_type(gid) ## tidy up H5Gclose(gid) H5Fclose(fid)
An identifier is no longer valid after it has been closed.
H5Iis_valid(h5identifier)
H5Iis_valid(h5identifier)
h5identifier |
Object of class H5IdComponent. |
A logical of length 1. TRUE
is the identifier is valid,
FALSE
if not.
h5file <- system.file("testfiles", "h5ex_t_array.h5", package="rhdf5") fid <- H5Fopen(h5file) ## test whether the identifer to the opened file is valid H5Iis_valid(fid) ## the file ID is no longer valid after it has been closed H5Fclose(fid) H5Iis_valid(fid)
h5file <- system.file("testfiles", "h5ex_t_array.h5", package="rhdf5") fid <- H5Fopen(h5file) ## test whether the identifer to the opened file is valid H5Iis_valid(fid) ## the file ID is no longer valid after it has been closed H5Fclose(fid) H5Iis_valid(fid)
Copy a link from one location to another
H5Lcopy(h5loc, name, h5loc_dest, name_dest, lcpl = NULL, lapl = NULL)
H5Lcopy(h5loc, name, h5loc_dest, name_dest, lcpl = NULL, lapl = NULL)
h5loc |
An object of class H5IdComponent representing a H5 location identifier (file or group) where the new link is placed. |
name |
The name of the link to be copied. |
h5loc_dest |
An object of class H5IdComponent representing the destination file or group where a copied or moved link should be created. |
name_dest |
The name of the link to be created when copying or moving. |
lcpl , lapl
|
Link creation and link access property lists. If left as
|
H5Lcreate_external()
creates a new external link. An external
link is a soft link to an object in a different HDF5 file from the location
of the link.
H5Lcreate_external(target_file_name, target_obj_name, link_loc, link_name)
H5Lcreate_external(target_file_name, target_obj_name, link_loc, link_name)
target_file_name |
Name of the external HDF5 to link to |
target_obj_name |
Path to the object in the file specified by
|
link_loc |
H5IdComponent object giving the location where the new link should be created. Can represent an HDF5 file or group. |
link_name |
Name (path) of the new link, relative to the location of
|
## The example below creates a new HDF5 file in a temporary director, and then ## links to the group "/foo" found in the file "multiple_dtypes.h5" ## distributed with the package. h5File1 <- system.file("testfiles", "multiple_dtypes.h5", package="rhdf5") h5File2 <- tempfile(pattern = "H5L_2_", fileext = ".h5") h5createFile(h5File2) ## open the new file & create a link to the group "/foo" in the original file fid <- H5Fopen(h5File2) H5Lcreate_external(target_file_name = h5File1, target_obj_name = "/foo", link_loc = fid, link_name = "/external_link") H5Fclose(fid) ## check the new file has a group called "/external_link" h5ls(h5File2)
## The example below creates a new HDF5 file in a temporary director, and then ## links to the group "/foo" found in the file "multiple_dtypes.h5" ## distributed with the package. h5File1 <- system.file("testfiles", "multiple_dtypes.h5", package="rhdf5") h5File2 <- tempfile(pattern = "H5L_2_", fileext = ".h5") h5createFile(h5File2) ## open the new file & create a link to the group "/foo" in the original file fid <- H5Fopen(h5File2) H5Lcreate_external(target_file_name = h5File1, target_obj_name = "/foo", link_loc = fid, link_name = "/external_link") H5Fclose(fid) ## check the new file has a group called "/external_link" h5ls(h5File2)
Remove a link from a group
H5Ldelete(h5loc, name)
H5Ldelete(h5loc, name)
h5loc |
An object of class H5IdComponent representing a H5 location identifier (file or group). |
name |
The name of the link to be deleted. |
h5file <- tempfile(pattern = "_ex_H5L.h5") # create an hdf5 file and a group h5createFile( h5file ) h5createGroup(h5file,"/foo") # reopen file and confirm "/foo" exists but "/baa" does not fid <- H5Fopen(h5file) H5Lexists(fid, "/foo") # remove the link to "/foo" and confirm it no longer exists H5Ldelete(fid, "/foo") H5Lexists(fid, "/foo") H5Fclose(fid)
h5file <- tempfile(pattern = "_ex_H5L.h5") # create an hdf5 file and a group h5createFile( h5file ) h5createGroup(h5file,"/foo") # reopen file and confirm "/foo" exists but "/baa" does not fid <- H5Fopen(h5file) H5Lexists(fid, "/foo") # remove the link to "/foo" and confirm it no longer exists H5Ldelete(fid, "/foo") H5Lexists(fid, "/foo") H5Fclose(fid)
Confirm existence of a link
H5Lexists(h5loc, name)
H5Lexists(h5loc, name)
h5loc |
An object of class H5IdComponent representing a H5 location identifier (file or group). |
name |
The name of the link to be checked |
H5Lget_info()
identifies the type of link specified by the the h5loc
and name
arguments. This is more limited than the equivalent function in
the standard HDF5 library.
H5Lget_info(h5loc, name)
H5Lget_info(h5loc, name)
h5loc |
An object of class H5IdComponent representing a H5 location identifier (file or group). |
name |
The name of the link to be queried. |
A character vector of length 1 giving the type of link. Possible
values are:
H5L_TYPE_HARD
, H5L_TYPE_SOFT
, H5L_TYPE_EXTERNAL
, H5L_TYPE_ERROR
A list of all valid HDF5 identifiers. H5 objects should be closed after usage to release resources.
h5listIdentifier() h5validObjects(native = FALSE)
h5listIdentifier() h5validObjects(native = FALSE)
native |
An object of class |
h5validObjects
returns a list of H5IdComponent
objects. h5listIdentifier
prints the valid identifiers on screen and
returns NULL.
Bernd Fischer, Mike Smith
h5File <- tempfile("ex_list_identifier.h5") h5createFile(h5File) # create groups h5createGroup(h5File,"foo") h5listIdentifier() h5validObjects()
h5File <- tempfile("ex_list_identifier.h5") h5createFile(h5File) # create groups h5createGroup(h5File,"foo") h5listIdentifier() h5validObjects()
Move a link within an HDF5 file
H5Lmove(h5loc, name, h5loc_dest, name_dest, lcpl = NULL, lapl = NULL)
H5Lmove(h5loc, name, h5loc_dest, name_dest, lcpl = NULL, lapl = NULL)
h5loc |
An object of class H5IdComponent representing a H5 location identifier (file or group) where the new link is placed. |
name |
The name of the link to be moved. |
h5loc_dest |
H5IdComponent object representing the H5 location where the new link should be created. |
name_dest |
Name of the new link to be created |
lcpl , lapl
|
Link creation and link access property lists to be
associated with the new link. Leaving these arguments as |
## create an HDF5 file with a single group ## that contains a dataset of 10 numbers h5file <- tempfile(fileext = ".h5") h5createFile(h5file) h5createGroup(h5file, "/foo") h5write(1:10, h5file, name = "/foo/vector1") ## check the structure is what we expect h5ls(h5file) ## open the file, the group where the dataset currently is ## and the root group fid <- H5Fopen(name = h5file) gid1 <- H5Gopen(fid, "/foo") gid2 <- H5Gopen(fid, "/") ## move the dataset to the root of the file and rename it H5Lmove(gid1, "vector1", gid2, "vector_new") h5closeAll() ## check the dataset has moved out of the foo group h5ls(h5file) ## we can also provide the ID of the HDF5 file ## and use the "name" arguments to move between groups fid <- H5Fopen(name = h5file) H5Lmove(fid, "/vector_new", fid, "/foo/vector_newer") H5Fclose(fid) h5ls(h5file)
## create an HDF5 file with a single group ## that contains a dataset of 10 numbers h5file <- tempfile(fileext = ".h5") h5createFile(h5file) h5createGroup(h5file, "/foo") h5write(1:10, h5file, name = "/foo/vector1") ## check the structure is what we expect h5ls(h5file) ## open the file, the group where the dataset currently is ## and the root group fid <- H5Fopen(name = h5file) gid1 <- H5Gopen(fid, "/foo") gid2 <- H5Gopen(fid, "/") ## move the dataset to the root of the file and rename it H5Lmove(gid1, "vector1", gid2, "vector_new") h5closeAll() ## check the dataset has moved out of the foo group h5ls(h5file) ## we can also provide the ID of the HDF5 file ## and use the "name" arguments to move between groups fid <- H5Fopen(name = h5file) H5Lmove(fid, "/vector_new", fid, "/foo/vector_newer") H5Fclose(fid) h5ls(h5file)
List the content of an HDF5 file.
h5ls( file, recursive = TRUE, all = FALSE, datasetinfo = TRUE, index_type = h5default("H5_INDEX"), order = h5default("H5_ITER"), s3 = FALSE, s3credentials = NULL, native = FALSE )
h5ls( file, recursive = TRUE, all = FALSE, datasetinfo = TRUE, index_type = h5default("H5_INDEX"), order = h5default("H5_ITER"), s3 = FALSE, s3credentials = NULL, native = FALSE )
file |
The filename (character) of the file in which the dataset will
be located. You can also provide an object of class H5IdComponent
representing a H5 location identifier (file or group). See |
recursive |
If |
all |
If |
datasetinfo |
If |
index_type |
See |
order |
See |
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. |
native |
An object of class |
h5ls
returns a data.frame
with the file content.
Bernd Fischer, Mike L. Smith
https://portal.hdfgroup.org/display/HDF5
h5File <- tempfile(pattern = "ex_dump.h5") h5createFile(h5File) # create groups h5createGroup(h5File,"foo") h5createGroup(h5File,"foo/foobaa") # write a matrix B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) attr(B, "scale") <- "liter" h5write(B, h5File,"foo/B") # list content of hdf5 file h5ls(h5File,all=TRUE) # list content of an hdf5 file in a public S3 bucket h5ls(file = "https://rhdf5-public.s3.eu-central-1.amazonaws.com/h5ex_t_array.h5", s3 = TRUE)
h5File <- tempfile(pattern = "ex_dump.h5") h5createFile(h5File) # create groups h5createGroup(h5File,"foo") h5createGroup(h5File,"foo/foobaa") # write a matrix B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) attr(B, "scale") <- "liter" h5write(B, h5File,"foo/B") # list content of hdf5 file h5ls(h5File,all=TRUE) # list content of an hdf5 file in a public S3 bucket h5ls(file = "https://rhdf5-public.s3.eu-central-1.amazonaws.com/h5ex_t_array.h5", s3 = TRUE)
Close an HDF5 object
H5Oclose(h5obj)
H5Oclose(h5obj)
h5obj |
An object of class H5IdComponent representing an open HDF5 object. |
Copies an HDF5 object
H5Ocopy(h5loc, name, h5loc_dest, name_dest, obj_cpy_pl = NULL, lcpl = NULL)
H5Ocopy(h5loc, name, h5loc_dest, name_dest, obj_cpy_pl = NULL, lcpl = NULL)
h5loc |
An object of class H5IdComponent representing an open HDF5 object where the source obiect should be copied from. |
name |
Character vector of length 1, giving the name of the source object to be copied. |
h5loc_dest |
An object of class H5IdComponent representing an open HDF5 object where the new copy should be created. |
name_dest |
Character vector of length 1, giving the name of the new object to be created. |
obj_cpy_pl , lcpl
|
H5IdComponent objects representing object copy and link creation property lists
respectively. If left as |
## Create a temporary copy of an example file check the contents example_file <- system.file("testfiles", "h5ex_t_array.h5", package="rhdf5") file.copy(example_file, tempdir()) h5_file <- file.path(tempdir(), "h5ex_t_array.h5") h5ls(h5_file) ## open the example file and create a new, empty, file fid1 <- H5Fopen( h5_file ) h5_file2 <- tempfile(fileext = ".h5") fid2 <- H5Fcreate( h5_file2 ) ## We can copy a dataset inside the same file H5Ocopy(h5loc = fid1, name = "DS1", h5loc_dest = fid1, name_dest = "DS2") ## Or to a different file H5Ocopy(h5loc = fid1, name = "DS1", h5loc_dest = fid2, name_dest = "DS1_copy") ## if we want to create a new group hierarchy we can use a link creation property list lcpl <- H5Pcreate("H5P_LINK_CREATE") H5Pset_create_intermediate_group( lcpl, create_groups = TRUE ) H5Ocopy(h5loc = fid1, name = "DS1", h5loc_dest = fid2, name_dest = "/foo/baa/DS1_nested", lcpl = lcpl) ## tidy up H5Pclose(lcpl) H5Fclose(fid1) H5Fclose(fid2) ## Check we now have groups DS1 and DS2 in the original file h5ls( h5_file ) ## Check we have a copy of DS1 at the root and nests in the new file h5ls( h5_file2 )
## Create a temporary copy of an example file check the contents example_file <- system.file("testfiles", "h5ex_t_array.h5", package="rhdf5") file.copy(example_file, tempdir()) h5_file <- file.path(tempdir(), "h5ex_t_array.h5") h5ls(h5_file) ## open the example file and create a new, empty, file fid1 <- H5Fopen( h5_file ) h5_file2 <- tempfile(fileext = ".h5") fid2 <- H5Fcreate( h5_file2 ) ## We can copy a dataset inside the same file H5Ocopy(h5loc = fid1, name = "DS1", h5loc_dest = fid1, name_dest = "DS2") ## Or to a different file H5Ocopy(h5loc = fid1, name = "DS1", h5loc_dest = fid2, name_dest = "DS1_copy") ## if we want to create a new group hierarchy we can use a link creation property list lcpl <- H5Pcreate("H5P_LINK_CREATE") H5Pset_create_intermediate_group( lcpl, create_groups = TRUE ) H5Ocopy(h5loc = fid1, name = "DS1", h5loc_dest = fid2, name_dest = "/foo/baa/DS1_nested", lcpl = lcpl) ## tidy up H5Pclose(lcpl) H5Fclose(fid1) H5Fclose(fid2) ## Check we now have groups DS1 and DS2 in the original file h5ls( h5_file ) ## Check we have a copy of DS1 at the root and nests in the new file h5ls( h5_file2 )
Find the number of attributes associated with an HDF5 object
H5Oget_num_attrs(h5obj) H5Oget_num_attrs_by_name(h5loc, name)
H5Oget_num_attrs(h5obj) H5Oget_num_attrs_by_name(h5loc, name)
h5obj |
An object of class H5IdComponent representing a H5 object identifier (file, group, or dataset). |
h5loc |
An object of class H5IdComponent representing a H5 location identifier (file or group). |
name |
The name of the object to be checked. |
These functions are not part of the standard HDF5 C API.
Returns a vector of length 1 containing the number of attributes the specified object has.
Create a hard link to an object in an HDF5 file
H5Olink(h5obj, h5loc, newLinkName, lcpl = NULL, lapl = NULL)
H5Olink(h5obj, h5loc, newLinkName, lcpl = NULL, lapl = NULL)
h5obj |
An object of class H5IdComponent representing the object to be linked to. |
h5loc |
An object of class H5IdComponent representing the location at which the object is to be linked. Can represent a file, group, dataset, datatype or attribute. |
newLinkName |
Character string giving the name of the new link. This should be relative to
|
lcpl , lapl
|
H5IdComponent objects representing link creation and link access property lists
respectively. If left as |
## Create a temporary copy of an example file, and open it example_file <- system.file("testfiles", "h5ex_t_array.h5", package="rhdf5") file.copy(example_file, tempdir()) h5_file <- file.path(tempdir(), "h5ex_t_array.h5") fid <- H5Fopen( h5_file ) ## create a new group without a location in the file gid <- H5Gcreate_anon(fid) ## create link to newly create group ## relative to the file identifier H5Olink(h5obj = gid, h5loc = fid, newLinkName = "foo") ## tidy up H5Gclose(gid) H5Fclose(fid) ## Check we now have a "/foo" group h5ls( h5_file )
## Create a temporary copy of an example file, and open it example_file <- system.file("testfiles", "h5ex_t_array.h5", package="rhdf5") file.copy(example_file, tempdir()) h5_file <- file.path(tempdir(), "h5ex_t_array.h5") fid <- H5Fopen( h5_file ) ## create a new group without a location in the file gid <- H5Gcreate_anon(fid) ## create link to newly create group ## relative to the file identifier H5Olink(h5obj = gid, h5loc = fid, newLinkName = "foo") ## tidy up H5Gclose(gid) H5Fclose(fid) ## Check we now have a "/foo" group h5ls( h5_file )
Open an object in an HDF5 file
H5Oopen(h5loc, name)
H5Oopen(h5loc, name)
h5loc |
An object of class H5IdComponent |
name |
Path to the object to be opened. This should be relative to
|
An object of class H5IdComponent if the open operation was
successful. FALSE
otherwise.
h5File <- tempfile(pattern = "ex_H5O.h5") # create an hdf5 file and write something h5createFile(h5File) h5createGroup(h5File,"foo") B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) h5write(B, h5File,"foo/B") # reopen file and dataset and get object info fid <- H5Fopen(h5File) oid = H5Oopen(fid, "foo") H5Oget_num_attrs(oid) H5Oclose(oid) H5Fclose(fid)
h5File <- tempfile(pattern = "ex_H5O.h5") # create an hdf5 file and write something h5createFile(h5File) h5createGroup(h5File,"foo") B = array(seq(0.1,2.0,by=0.1),dim=c(5,2,2)) h5write(B, h5File,"foo/B") # reopen file and dataset and get object info fid <- H5Fopen(h5File) oid = H5Oopen(fid, "foo") H5Oget_num_attrs(oid) H5Oclose(oid) H5Fclose(fid)
Get and set the size of the chunks used to store a chunked layout dataset
H5Pset_chunk(h5plist, dim) H5Pget_chunk(h5plist)
H5Pset_chunk(h5plist, dim) H5Pget_chunk(h5plist)
h5plist |
An object of class H5IdComponent representing a dataset creation property list. |
dim |
The chunk size used to store the dataset. This argument should be an integer vector of the same length as the number of dimensions of the dataset the dataset creation property list will be applied to. |
Note that a necessary side effect of running this function is that the
layout of the dataset will be changes to H5D_CHUNKED
if it is not already set to this.
Set parameters for the raw data chunk cache
H5Pset_chunk_cache(h5plist, rdcc_nslots, rdcc_nbytes, rdcc_w0)
H5Pset_chunk_cache(h5plist, rdcc_nslots, rdcc_nbytes, rdcc_w0)
h5plist |
Object of class H5IdComponent representing a dataset access property list. |
rdcc_nslots |
Integer defining the number of chunk slots in the raw data chunk cache for this dataset. |
rdcc_nbytes |
Integer setting the total size of the raw data chunk cache for this dataset in bytes. In most cases increasing this number will improve performance, as long as you have enough free memory. The default size is 1 MB |
rdcc_w0 |
Numeric value defining the chunk preemption policy. Must be between
|
Get and set whether to create missing intermediate groups
H5Pset_create_intermediate_group(h5plist, create_groups = TRUE) H5Pget_create_intermediate_group(h5plist)
H5Pset_create_intermediate_group(h5plist, create_groups = TRUE) H5Pget_create_intermediate_group(h5plist)
h5plist |
An object of class H5IdComponent representing a link creation property list. |
create_groups |
A logical of length 1 specifying whether missing
groups should be created when a new object is created. Default is |
pid <- H5Pcreate("H5P_LINK_CREATE") ## by default intermediate groups are not created H5Pget_create_intermediate_group( pid ) ## Change the setting so groups will be created H5Pget_create_intermediate_group( pid ) ## tidy up H5Pclose(pid)
pid <- H5Pcreate("H5P_LINK_CREATE") ## by default intermediate groups are not created H5Pget_create_intermediate_group( pid ) ## Change the setting so groups will be created H5Pget_create_intermediate_group( pid ) ## tidy up H5Pclose(pid)
Set the time when fill values are written to a dataset
H5Pset_fill_time(h5plist, fill_time = h5default("H5D_FILL_TIME")) H5Pget_fill_time(h5plist)
H5Pset_fill_time(h5plist, fill_time = h5default("H5D_FILL_TIME")) H5Pget_fill_time(h5plist)
h5plist |
An object of class H5IdComponent representing a dataset creation property list. |
fill_time |
When the fill values should be written. Possible options
can be listed with |
H5Pset_fill_value
sets the fill value for a dataset in the dataset creation property list.
H5Pset_fill_value(h5plist, value)
H5Pset_fill_value(h5plist, value)
h5plist |
An object of class H5IdComponent representing a dataset creation property list. |
value |
The default fill value of the dataset. A vector of length 1. |
H5P_fill_time,H5Pfill_value_defined
Possible options for the layout
argument are:
H5D_COMPACT
H5D_CONTIGUOUS
H5D_CHUNKED
H5D_VIRTUAL
H5Pset_layout(h5plist, layout = h5default("H5D")) H5Pget_layout(h5plist)
H5Pset_layout(h5plist, layout = h5default("H5D")) H5Pget_layout(h5plist)
h5plist |
An object of class H5IdComponent representing a dataset creation property list. |
layout |
A character giving the name of a dataset layout type. |
The names of the layout types can also be obtained via h5const("H5D")
.
Control the range of HDF5 library versions that will be compatible with a file.
H5Pset_libver_bounds( h5plist, libver_low = "H5F_LIBVER_EARLIEST", libver_high = "H5F_LIBVER_LATEST" ) H5Pget_libver_bounds(h5plist)
H5Pset_libver_bounds( h5plist, libver_low = "H5F_LIBVER_EARLIEST", libver_high = "H5F_LIBVER_LATEST" ) H5Pget_libver_bounds(h5plist)
h5plist |
H5IdComponent object representing a file access property list. |
libver_low , libver_high
|
Define the earliest and latest versions of the HDF5 library that will be used when writing object in the file. |
Return information about the filter pipeline applied to a dataset creation property list.
H5Pall_filters_avail(h5plist) H5Pget_nfilters(h5plist) H5Pget_filter(h5plist, idx)
H5Pall_filters_avail(h5plist) H5Pget_nfilters(h5plist) H5Pget_filter(h5plist, idx)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
idx |
Integer of length 1. This argument selects which filter to return information about. Indexing is R-style 1-based. |
H5Pall_filters_avail()
checks whether all filters required to process a
dataset are available to rhdf5. This can be required if reading files
created with other HDF5 software.
H5Pget_nfilters()
returns the number of
filters in the dataset chunk processing pipeline.
H5Pget_filter()
provides details of a specific filter in the pipeline. This includes the
filter name and the parameters provided to it e.g. compression level.
H5Pclose()
terminates access to a property list. All property lists
should be closed when they no longer need to be accessed. This
frees resources used by the property list. Failing to call H5Pclose()
can lead to memory leakage over time.
H5Pclose(h5plist)
H5Pclose(h5plist)
h5plist |
H5IdComponent object representing the property list to close. |
Copy an existing property list to create a new property list
H5Pcopy(h5plist)
H5Pcopy(h5plist)
h5plist |
H5IdComponent object representing the property list to be copied. |
Create a new HDF5 property list
H5Pcreate(type = h5default("H5P"), native = FALSE)
H5Pcreate(type = h5default("H5P"), native = FALSE)
type |
A character name of a property list type. See |
native |
Defunct! Doesn't achieve anything for property lists. |
Determine whether a property list has a fill value defined
H5Pfill_value_defined(h5plist)
H5Pfill_value_defined(h5plist)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
Note that the return value for this function is slightly different from the C version. The C API provides three return types and can, in the case that a fill value is defined, differentiate whether the value is the HDF5 library default or has been set by the application.
TRUE
if the fill value is defined, FALSE
if not. Will return
NULL
if there is a problem determining the status of the fill value.
Return the property list class identifier for a property list
H5Pget_class(h5plist)
H5Pget_class(h5plist)
h5plist |
H5IdComponent object representing any type of HDF5 property list. |
Get version information for objects in a file creation property list
H5Pget_version(h5plist)
H5Pget_version(h5plist)
h5plist |
H5IdComponent object representing the file creation property list |
Named integer vector
Set whether to record timestamps for operations performed on an HDF5 object.
H5Pset_obj_track_times(h5plist, track_times = TRUE) H5Pget_obj_track_times(h5plist)
H5Pset_obj_track_times(h5plist, track_times = TRUE) H5Pget_obj_track_times(h5plist)
h5plist |
An H5IdComponent object representing an object creation property list. |
track_times |
|
Objects created using high-level rhdf5 functions like
h5createDataset()
will have this setting turned off. This was done to
ensure otherwise identical files returned the same md5 hash. This differs
from the default setting in HDF5, which is for objects to record the times
operations were performed on them.
Add the BLOSC filter to the chunk processing pipeline.
H5Pset_blosc(h5plist, h5tid, method = 1L, level = 6L, shuffle = TRUE)
H5Pset_blosc(h5plist, h5tid, method = 1L, level = 6L, shuffle = TRUE)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
h5tid |
HDF5 data type id |
method |
Integer defining which of the compression algorithms provided by BLOSC should be used. (See the details section for the mapping between integers and algorithms). |
level |
Compression level to be used by the selected algorithm. |
shuffle |
Logical defining whether the bit-shuffle algorithm should be used prior to compression. This makes use of the shuffle implementation provide by BLOSC, rather than the HDF5 version. |
Add the BZIP2 filter to the chunk processing pipeline.
H5Pset_bzip2(h5plist, level = 2L)
H5Pset_bzip2(h5plist, level = 2L)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
level |
Compression level to be used by the selected algorithm. |
Valid values for the compression level range from 0 (no compression) to 9
(best compression, slowest speed). Note that applying this function with
level = 0
does not mean the filter is removed. It is still part of the
filter pipeline, but no compression is performed. The filter will still need
to be available on any system that reads a file created with this setting
H5Pset_deflate(h5plist, level)
H5Pset_deflate(h5plist, level)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
level |
Integer giving the compression level to use. Valid values are from 0 to 9. |
The read-only S3 virtual file driver can be used to read files hosted remotely on Amazon's S3 storage.
H5Pset_fapl_ros3(h5plist, s3credentials = NULL)
H5Pset_fapl_ros3(h5plist, s3credentials = NULL)
h5plist |
H5IdComponent object representing a file access property list. |
s3credentials |
Either |
To access files in a private Amazon S3 bucket you will need to
provide three additional details: The AWS region where the files are
hosted, your AWS access key ID, and your AWS secret access key. More
information on how to obtain AWS access keys can be found at
https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys.
These are provided as a list to the s3credentials
argument. If you
are accessing public data this argument should be NULL
.
## this doesn't work on the Bioconductor Mac build machine ## Not run: pid <- H5Pcreate("H5P_FILE_ACCESS") H5Pset_fapl_ros3( pid ) H5Pclose(pid) ## End(Not run)
## this doesn't work on the Bioconductor Mac build machine ## Not run: pid <- H5Pcreate("H5P_FILE_ACCESS") H5Pset_fapl_ros3( pid ) H5Pclose(pid) ## End(Not run)
Add a filter to the dataset filter pipeline.
H5Pset_filter(h5plist, filter_id, is_mandatory = FALSE, cd_values)
H5Pset_filter(h5plist, filter_id, is_mandatory = FALSE, cd_values)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
filter_id |
Integer of length 1, giving the ID of the filter to be used. |
is_mandatory |
Logical of length 1. Filters can be either optional or
mandatory. If this argument is set to |
cd_values |
Integer vector giving parameters to be supplied to the filter. No guidance is given for the number of values supplied here, it is specific to each filter and the user is expected to know appropriate options for the requested filter. |
Get and set the 1/2 rank of an indexed storage B-tree
H5Pset_istore_k(h5plist, ik) H5Pget_istore_k(h5plist)
H5Pset_istore_k(h5plist, ik) H5Pget_istore_k(h5plist)
h5plist |
H5IdComponent object representing the file creation property list |
ik |
chunked Storage B-tree 1/2 rank |
Add the LZF filter to the chunk processing pipeline.
H5Pset_lzf(h5plist, h5tid)
H5Pset_lzf(h5plist, h5tid)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
h5tid |
HDF5 data type id |
Add the N-Bit filter to the chunk processing pipeline.
H5Pset_nbit(h5plist)
H5Pset_nbit(h5plist)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
Returns (invisibly) an integer vector of length 1. The only element of this vector will be non-negative if the filter was set successfully and negative otherwise.
Add the shuffle filter to the chunk processing pipeline.
H5Pset_shuffle(h5plist)
H5Pset_shuffle(h5plist)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
Returns (invisibly) an integer vector of length 1. The only element of this vector will be non-negative if the filter was set successfully and negative otherwise.
Get and set the sizes of offsets and lengths used in an HDF5 file
H5Pset_sizes(h5plist, sizeof_addr, sizeof_size) H5Pget_sizes(h5plist)
H5Pset_sizes(h5plist, sizeof_addr, sizeof_size) H5Pget_sizes(h5plist)
h5plist |
H5IdComponent object representing the file creation property list |
sizeof_addr |
Offset size in bytes |
sizeof_size |
Length size in bytes |
Get and set the size of the symbol table B-tree 1/2 rank and the leaf node 1/2 size
H5Pset_sym_k(h5plist, ik, lk) H5Pget_sym_k(h5plist)
H5Pset_sym_k(h5plist, ik, lk) H5Pget_sym_k(h5plist)
h5plist |
H5IdComponent object representing the file creation property list |
ik |
Symbol table B-tree 1/2 rank |
lk |
Symbol table leaf node 1/2 size |
Add the SZIP compression filter to the chunk processing pipeline.
H5Pset_szip(h5plist, options_mask, pixels_per_block)
H5Pset_szip(h5plist, options_mask, pixels_per_block)
h5plist |
Object of class H5IdComponent representing a dataset creation property list. |
options_mask , pixels_per_block
|
Integer vectors of length 1, setting parameters of the SZIP algorithm. See https://portal.hdfgroup.org/display/HDF5/H5P_SET_SZIP for more details. |
https://portal.hdfgroup.org/display/HDF5/Szip+Compression+in+HDF+Products
Get and set the user block size
H5Pset_userblock(h5plist, size) H5Pget_userblock(h5plist)
H5Pset_userblock(h5plist, size) H5Pget_userblock(h5plist)
h5plist |
H5IdComponent object representing the file creation property list |
size |
of the user block in bytes |
The H5R
functions can be used for creating or working with
references to specific objects and data regions in an HDF5 file.
Mike Smith
library(rhdf5) ## first we'll create a file with a group named "foo" and a ## 1-dimensional dataset named "baa" inside that group. file_name <- tempfile(fileext = ".h5") h5createFile(file_name) h5createGroup(file = file_name, group = "/foo") h5write(1:100, file=file_name, name="/foo/baa") fid <- H5Fopen(file_name) ref_to_group <- H5Rcreate(fid, name = "/foo") ref_to_dataset <- H5Rcreate(fid, name = "/foo/baa") two_refs <- c(ref_to_group, ref_to_dataset) two_refs ## the size of this dataspace is the number of object references ## we want to store sid <- H5Screate_simple(2) tid <- H5Tcopy(dtype_id = "H5T_STD_REF_OBJ") did <- H5Dcreate(fid, name = "object_refs", dtype_id = tid, h5space = sid) H5Dwrite(did, two_refs) H5Dclose(did) H5Sclose(sid) H5Fclose(fid)
library(rhdf5) ## first we'll create a file with a group named "foo" and a ## 1-dimensional dataset named "baa" inside that group. file_name <- tempfile(fileext = ".h5") h5createFile(file_name) h5createGroup(file = file_name, group = "/foo") h5write(1:100, file=file_name, name="/foo/baa") fid <- H5Fopen(file_name) ref_to_group <- H5Rcreate(fid, name = "/foo") ref_to_dataset <- H5Rcreate(fid, name = "/foo/baa") two_refs <- c(ref_to_group, ref_to_dataset) two_refs ## the size of this dataspace is the number of object references ## we want to store sid <- H5Screate_simple(2) tid <- H5Tcopy(dtype_id = "H5T_STD_REF_OBJ") did <- H5Dcreate(fid, name = "object_refs", dtype_id = tid, h5space = sid) H5Dwrite(did, two_refs) H5Dclose(did) H5Sclose(sid) H5Fclose(fid)
Creates a reference to an object or dataset selection inside an HDF5 file.
H5Rcreate(h5loc, name, ref_type = "H5R_OBJECT", h5space = NULL)
H5Rcreate(h5loc, name, ref_type = "H5R_OBJECT", h5space = NULL)
h5loc |
An |
name |
Character string giving the name of the object to be referenced,
relative to the location given by |
ref_type |
The type of reference to create. Accepts either |
h5space |
An object of class |
An H5Ref object storing the reference.
Given a reference and the file to which that reference applies,
H5Rdeference()
will open the reference object and return an identifier.
H5Rdereference(ref, h5loc)
H5Rdereference(ref, h5loc)
ref |
|
h5loc |
An |
If ref
contains more than one reference, only the first reference
will be used. It must be subset with [
if one of the other stored
references should be opened.
An object of class H5IdComponent
representing the opened object
referenced by ref
. This should be closed with the appropriate function
e.g. H5Dclose()
, H5Oclose()
, etc. when no longer needed.
A class representing one or more HDF5 references.
## S4 method for signature 'H5Ref' show(object) ## S4 method for signature 'H5Ref' length(x) ## S4 method for signature 'H5Ref' c(x, ...) ## S4 method for signature 'H5Ref' x[i]
## S4 method for signature 'H5Ref' show(object) ## S4 method for signature 'H5Ref' length(x) ## S4 method for signature 'H5Ref' c(x, ...) ## S4 method for signature 'H5Ref' x[i]
object |
Object of class |
x |
An |
... |
Additional |
i |
Integer vector giving the indices of references to select. |
The length of the val
slot is dependent on both the number and type of
references stored in the object. H5R_OBJECT
references are stored in 8
bytes, while H5R_DATASET_REGION
references require 12 bytes. The length
of val
will then be a multiple of 8 or 12 respectively. This also means
that references of different types cannot be combined in a single object.
show(H5Ref)
: Print details of the object to screen.
length(H5Ref)
: Return the number of references stored in an H5Ref
object.
c(H5Ref)
: Combine two or more H5Ref
objects. Objects must all
contain the same type of reference, either H5R_OBJECT
or
H5R_DATASET_REFERENCE
.
[
: Subset an H5Ref
object.
val
raw
vector containing the byte-level representation of each
reference.
type
integer
of length 1, which maps to either H5R_OBJECT
or
H5R_DATASET_REGION
.
Return the name of the object that a reference points to
H5Rget_name(ref, h5loc)
H5Rget_name(ref, h5loc)
ref |
|
h5loc |
An |
Character string of length 1 giving the name of the referenced object.
Identify the type of object that a reference points to
H5Rget_obj_type(ref, h5loc)
H5Rget_obj_type(ref, h5loc)
ref |
|
h5loc |
An |
Character string of length 1 identifying the object type. Valid return
values are: "GROUP"
, "DATASET"
, and "NAMED_DATATYPE"
.
Given a dataset region reference, this function will return the dataspace and selection required to read the data points indicated by the reference.
H5Rget_region(ref, h5loc)
H5Rget_region(ref, h5loc)
ref |
An object of class |
h5loc |
An |
An object of class H5IdComponent
representing the dataspace of the
dataset that ref
points to. The dataspace will have the selection set
that matches the selection pointed to by ref
. This should be closed using
H5Sclose()
when no longer required.
Close and release a dataspace
H5Sclose(h5space)
H5Sclose(h5space)
h5space |
Object of class H5IdComponent representing the dataspace to be closed. |
Combines a hyperslab selection specified by start
, stride
, count
and
block
arguments with the current selection for the dataspace
represented by h5space
.
H5Scombine_hyperslab( h5space, op = h5default("H5S_SELECT"), start = NULL, stride = NULL, count = NULL, block = NULL )
H5Scombine_hyperslab( h5space, op = h5default("H5S_SELECT"), start = NULL, stride = NULL, count = NULL, block = NULL )
h5space |
H5IdComponent object representing a dataspace. |
op |
Character string defined the operation used to join the two
dataspaces. See |
start , stride , count , block
|
Integer vectors, each with length equal to the rank of the dataspace. These parameters define the new hyperslab to select. |
An H5IdComponent object representing a new dataspace with the generated selection.
H5Scombine_select()
, H5Sselect_hyperslab()
## create a 1 dimensional dataspace sid_1 <- H5Screate_simple(dims = 20) ## select a single block of 5 points in sid_1 ## this is equivalent to [11:16] in R syntax H5Sselect_hyperslab(sid_1, start = 11, stride = 1, block = 5, count = 1)# ## combine the existing selection with a new ## selection consisting of 2 blocks each of 1 point ## equivalent to [c(3,5)] in R syntax sid_2 <- H5Scombine_hyperslab(sid_1, op = "H5S_SELECT_OR", start = 3, stride = 2, block = 1, count = 2) ## confirm we have selected 5 in our original dataspace ## and 7 points in the newly created dataspace H5Sget_select_npoints(sid_1) H5Sget_select_npoints(sid_2) ## tidy up H5Sclose(sid_1) H5Sclose(sid_2)
## create a 1 dimensional dataspace sid_1 <- H5Screate_simple(dims = 20) ## select a single block of 5 points in sid_1 ## this is equivalent to [11:16] in R syntax H5Sselect_hyperslab(sid_1, start = 11, stride = 1, block = 5, count = 1)# ## combine the existing selection with a new ## selection consisting of 2 blocks each of 1 point ## equivalent to [c(3,5)] in R syntax sid_2 <- H5Scombine_hyperslab(sid_1, op = "H5S_SELECT_OR", start = 3, stride = 2, block = 1, count = 2) ## confirm we have selected 5 in our original dataspace ## and 7 points in the newly created dataspace H5Sget_select_npoints(sid_1) H5Sget_select_npoints(sid_2) ## tidy up H5Sclose(sid_1) H5Sclose(sid_2)
Combine two selections
H5Scombine_select(h5space1, op = h5default("H5S_SELECT"), h5space2)
H5Scombine_select(h5space1, op = h5default("H5S_SELECT"), h5space2)
h5space1 , h5space2
|
H5IdComponent objects representing a dataspaces. |
op |
Character string defined the operation used to join the two
dataspaces. See |
Returns an H5IdComponent object representing a new dataspace.
The new dataspace will have the same extent as h5space1
with the
hyperslab selection being the result of combining the selections of
h5space1
and h5space2
.
## create two 1 dimensional dataspaces ## of different sizes sid_1 <- H5Screate_simple(dims = 20) sid_2 <- H5Screate_simple(dims = 10) ## select a single block of 5 points in sid_1 ## this is equivalent to [11:16] in R syntax H5Sselect_hyperslab(sid_1, start = 11, stride = 1, block = 5, count = 1) ## select 2 blocks of 1 point from sid_2 ## equivalent to [c(3,5)] in R syntax H5Sselect_hyperslab(sid_2, start = 3, stride = 2, block = 1, count = 2) ## confirm we have select 5 and 2 points resepectively H5Sget_select_npoints(sid_1) H5Sget_select_npoints(sid_2) ## combine the two dataset selections keeping points that ## are in one or both of the selections sid_3 <- H5Scombine_select(sid_1, "H5S_SELECT_OR", sid_2) ## extent of the new dataset is the same as sid_1 sid_3 ## confirm the selection contains 7 points H5Sget_select_npoints(sid_3) ## tidy up H5Sclose(sid_1) H5Sclose(sid_2) H5Sclose(sid_3)
## create two 1 dimensional dataspaces ## of different sizes sid_1 <- H5Screate_simple(dims = 20) sid_2 <- H5Screate_simple(dims = 10) ## select a single block of 5 points in sid_1 ## this is equivalent to [11:16] in R syntax H5Sselect_hyperslab(sid_1, start = 11, stride = 1, block = 5, count = 1) ## select 2 blocks of 1 point from sid_2 ## equivalent to [c(3,5)] in R syntax H5Sselect_hyperslab(sid_2, start = 3, stride = 2, block = 1, count = 2) ## confirm we have select 5 and 2 points resepectively H5Sget_select_npoints(sid_1) H5Sget_select_npoints(sid_2) ## combine the two dataset selections keeping points that ## are in one or both of the selections sid_3 <- H5Scombine_select(sid_1, "H5S_SELECT_OR", sid_2) ## extent of the new dataset is the same as sid_1 sid_3 ## confirm the selection contains 7 points H5Sget_select_npoints(sid_3) ## tidy up H5Sclose(sid_1) H5Sclose(sid_2) H5Sclose(sid_3)
H5S_copy()
creates an exact copy of a given dataspace.
H5Scopy(h5space)
H5Scopy(h5space)
h5space |
Object of class H5IdComponent representing the dataspace to be copied. |
If the copying is successful returns an object of class
H5IdComponent representing the new dataspace. Otherwise returns
FALSE
.
Create a new dataspace of a specified type
H5Screate(type = h5default("H5S"), native = FALSE)
H5Screate(type = h5default("H5S"), native = FALSE)
type |
The type of dataspace to create. See |
native |
An object of class |
Returns an object of class H5IdComponent representing a dataspace.
Create a simple dataspace
H5Screate_simple(dims, maxdims, native = FALSE)
H5Screate_simple(dims, maxdims, native = FALSE)
dims |
A numeric vector defining the initial dimensions of the dataspace.
The length of |
maxdims |
A numeric vector with the same length length as |
native |
An object of class |
Returns an object of class H5IdComponent representing a dataspace.
Find the number of elements in a dataspace selection
H5Sget_select_npoints(h5space)
H5Sget_select_npoints(h5space)
h5space |
H5IdComponent object representing a dataspace. |
Find the size of a dataspace
H5Sget_simple_extent_dims(h5space)
H5Sget_simple_extent_dims(h5space)
h5space |
H5IdComponent object representing a dataspace. |
In HDF5 a dataspace is considered "simple" if it represents a regular N-dimensional array of points. Currently (HDF 1.10.7) all dataspaces are simple. Support for complex dataspaces is planned for future HDF versions.
H5Sis_simple(h5space)
H5Sis_simple(h5space)
h5space |
H5IdComponent object representing a dataspace. |
Set the selection region of a dataspace to include all elements
H5Sselect_all(h5space)
H5Sselect_all(h5space)
h5space |
H5IdComponent object representing a dataspace. |
Combines a hyperslab selection specified by start
, stride
, count
and
block
arguments with the current selection for the dataspace
represented by h5space
.
H5Sselect_hyperslab( h5space, op = h5default("H5S_SELECT"), start = NULL, stride = NULL, count = NULL, block = NULL )
H5Sselect_hyperslab( h5space, op = h5default("H5S_SELECT"), start = NULL, stride = NULL, count = NULL, block = NULL )
h5space |
H5IdComponent object representing a dataspace. |
op |
Character string defined the operation used to join the two
dataspaces. See |
start , stride , count , block
|
Integer vectors, each with length equal to the rank of the dataspace. These parameters define the new hyperslab to select. |
H5Sselect_hyperslab
is similar to, but subtly different from,
H5Scombine_hyperslab()
. The former modifies the selection of the
dataspace provided in the h5space
argument, while the later returns a
new dataspace with the combined selection.
## create a 1 dimensional dataspace sid_1 <- H5Screate_simple(dims = 20) ## select a single block of 5 points in sid_1 ## this is equivalent to [11:16] in R syntax H5Sselect_hyperslab(sid_1, start = 11, stride = 1, block = 5, count = 1) ## confirm we have selected 5 in our original dataspace H5Sget_select_npoints(sid_1) ## combine the existing selection with a new ## selection consisting of 2 blocks each of 1 point ## equivalent to [c(3,5)] in R syntax H5Sselect_hyperslab(sid_1, op = "H5S_SELECT_OR", start = 3, stride = 2, block = 1, count = 2) ## The dataspace now has 7 points selected H5Sget_select_npoints(sid_1) ## tidy up H5Sclose(sid_1)
## create a 1 dimensional dataspace sid_1 <- H5Screate_simple(dims = 20) ## select a single block of 5 points in sid_1 ## this is equivalent to [11:16] in R syntax H5Sselect_hyperslab(sid_1, start = 11, stride = 1, block = 5, count = 1) ## confirm we have selected 5 in our original dataspace H5Sget_select_npoints(sid_1) ## combine the existing selection with a new ## selection consisting of 2 blocks each of 1 point ## equivalent to [c(3,5)] in R syntax H5Sselect_hyperslab(sid_1, op = "H5S_SELECT_OR", start = 3, stride = 2, block = 1, count = 2) ## The dataspace now has 7 points selected H5Sget_select_npoints(sid_1) ## tidy up H5Sclose(sid_1)
Combines a hyperslab selection specified by start
, stride
, count
and
block
arguments with the current selection for the dataspace represented by
h5space
.
H5Sselect_index(h5space, index)
H5Sselect_index(h5space, index)
h5space |
H5IdComponent object representing a dataspace. |
index |
A list of integer indices. The length of the list corresponds to
the number of dimensions of the HDF5 array. If a list element is |
H5Sselect_hyperslab
is similar to, but subtly different from,
H5Scombine_hyperslab()
. The former modifies the selection of the
dataspace provided in the h5space
argument, while the later returns a new
dataspace with the combined selection.
## create a 1 dimensional dataspace sid <- H5Screate_simple(c(10,5,3)) ## Select elements that lie in in the rows 1-3, columns 2-4, ## and the entire 3rd dimension H5Sselect_index(sid, list(1:3, 2:4, NULL)) ## We can check the number of selected points. ## This should be 27 (3 * 3 * 3) H5Sget_select_npoints(sid) ## always close dataspaces after usage to free resources H5Sclose(sid)
## create a 1 dimensional dataspace sid <- H5Screate_simple(c(10,5,3)) ## Select elements that lie in in the rows 1-3, columns 2-4, ## and the entire 3rd dimension H5Sselect_index(sid, list(1:3, 2:4, NULL)) ## We can check the number of selected points. ## This should be 27 (3 * 3 * 3) H5Sget_select_npoints(sid) ## always close dataspaces after usage to free resources H5Sclose(sid)
Set the selection region of a dataspace to include no elements
H5Sselect_none(h5space)
H5Sselect_none(h5space)
h5space |
H5IdComponent object representing a dataspace. |
Check that a selection is valid
H5Sselect_valid(h5space)
H5Sselect_valid(h5space)
h5space |
H5IdComponent object representing a dataspace. |
Set the size of a dataspace
H5Sset_extent_simple(h5space, dims, maxdims)
H5Sset_extent_simple(h5space, dims, maxdims)
h5space |
H5IdComponent object representing a dataspace. |
dims |
Dimension of the dataspace. This argument is similar to the dim attribute of an array. |
maxdims |
Maximum extension of the dimension of the dataset in the
file. If not provided, it is set to When viewing the HDF5 dataset with other software (e.g. HDFView), the dimensions appear in inverted order, because the fastest changing dimension in R is the first one, and in C it's the last one. |
H5S_UNLIMITED
constantThe value for H5S_UNLIMITED
can be provided to the maxdims
argument of H5Screate_simple
to indicate that the maximum size of the corresponding dimension is unlimited.
H5Sunlimited()
H5Sunlimited()
Retrieve or set the character set to be used in a string datatype.
H5Tset_cset(dtype_id, cset = "ASCII") H5Tget_cset(dtype_id)
H5Tset_cset(dtype_id, cset = "ASCII") H5Tget_cset(dtype_id)
dtype_id |
ID of HDF5 datatype to query or modify. |
cset |
Encoding to use for string types. Valid options are 'ASCII' and 'UTF-8'. |
Create or modify an HDF5 enum datatype
H5Tenum_create(dtype_id = "H5T_NATIVE_INT") H5Tenum_insert(dtype_id, name, value)
H5Tenum_create(dtype_id = "H5T_NATIVE_INT") H5Tenum_insert(dtype_id, name, value)
dtype_id |
ID of HDF5 datatype to work with. For |
name |
The name of a the new enum member. This is analogous to a "level" in an R factor. |
value |
The value of the new member. Must be compatible with the base
datatype defined by |
H5Tinsert_enum()
returns an character representing the H5 identifier
of the new datatype.
H5Tset_precision()
is called for its side-effect of modifying the
existing datatype. It will invisibly
return TRUE
if this is successful FALSE
if not.
tid <- H5Tenum_create(dtype_id = "H5T_NATIVE_UCHAR") H5Tenum_insert(tid, name = "TRUE", value = 1L) H5Tenum_insert(tid, name = "FALSE", value = 0L)
tid <- H5Tenum_create(dtype_id = "H5T_NATIVE_UCHAR") H5Tenum_insert(tid, name = "TRUE", value = 1L) H5Tenum_insert(tid, name = "FALSE", value = 0L)
Get details of HDF5 data types
H5Tget_class(dtype_id) H5Tget_nmembers(dtype_id)
H5Tget_class(dtype_id) H5Tget_nmembers(dtype_id)
dtype_id |
ID of HDF5 datatype to work with. Normally created with
a function like |
H5Tget_class()
returns an character vector of length 1 giving the
class of the data type.
H5Tget_nmembers()
returns the number of members in the given
datatype. Will fail with an error if the supplied datatype is not of type
H5T_COMPUND
or H5T_ENUM
.
## create an enum datatype with two entries tid <- H5Tenum_create(dtype_id = "H5T_NATIVE_UCHAR") H5Tenum_insert(tid, name = "TRUE", value = 1L) H5Tenum_insert(tid, name = "FALSE", value = 0L) H5Tget_class(tid) H5Tget_nmembers(tid)
## create an enum datatype with two entries tid <- H5Tenum_create(dtype_id = "H5T_NATIVE_UCHAR") H5Tenum_insert(tid, name = "TRUE", value = 1L) H5Tenum_insert(tid, name = "FALSE", value = 0L) H5Tget_class(tid) H5Tget_nmembers(tid)
Retrieve or set the precision of an HDF5 datatype
H5Tset_precision(dtype_id, precision) H5Tget_precision(dtype_id)
H5Tset_precision(dtype_id, precision) H5Tget_precision(dtype_id)
dtype_id |
ID of HDF5 datatype to set precision of. |
precision |
The number of bytes of precision for the datatype. |
H5Tget_precision()
returns an integer giving the number of
significant bits used by the given datatype.
H5Tset_precision()
is call for its side-effect of modifying the
precision of a datatype. It will invisibly return TRUE
if this is
successful and will stop with an error if the operation fails.
Retrieve or set the type of padding used by string datatype
H5Tset_size(dtype_id = h5default(type = "H5T"), size) H5Tget_size(dtype_id)
H5Tset_size(dtype_id = h5default(type = "H5T"), size) H5Tget_size(dtype_id)
dtype_id |
ID of HDF5 datatype to query or modify. |
size |
The new datatype size in bytes. |
Retrieve or set the type of padding used by string datatype
H5Tset_strpad(dtype_id, strpad = "NULLPAD") H5Tget_strpad(dtype_id)
H5Tset_strpad(dtype_id, strpad = "NULLPAD") H5Tget_strpad(dtype_id)
dtype_id |
ID of HDF5 datatype to query or modify. |
strpad |
Character vector of length 1 specifying the type of padding
to use. Valid options are |
Copy an existing datatype
H5Tcopy(dtype_id = h5default(type = "H5T"))
H5Tcopy(dtype_id = h5default(type = "H5T"))
dtype_id |
Datatype to copy. Can either be a character
specifying a predefined HDF5 datatype (see |
Determine whether a datatype is a variable length string
H5Tis_variable_str(dtype_id)
H5Tis_variable_str(dtype_id)
dtype_id |
ID of HDF5 datatype to query. |
Returns the version number of the Bioconductor package rhdf5 and the C-library libhdf5.
h5version()
h5version()
A list of major, minor and release number.
Bernd Fischer, Mike L. Smith
h5version()
h5version()
Determine whether a filter is available on this system
H5Zfilter_avail(filter_id)
H5Zfilter_avail(filter_id)
filter_id |
Integer representing the ID of the filter to be checked. |
The rhdf5 package provides two categories of functions:
h5
functions are high-level R functions that provide a convenient way of accessing HDF5 files
H5
functions mirror much of the the HDF5 C API