H5-attributs {hdf5r.Extra} | R Documentation |
Manipulate HDF5 attributes
Description
Functions to get, set or delete HDF5 attributes for an existing link.
Usage
h5Attr(x, which, ...)
h5Attributes(x, ...)
h5AttrNames(x, ...)
h5DeleteAttr(x, which, ...)
h5WriteAttr(x, which, robj, ...)
## S3 method for class 'H5D'
h5Attr(x, which, ...)
## S3 method for class 'H5Group'
h5Attr(x, which, name = NULL, ...)
## S3 method for class 'H5File'
h5Attr(x, which, name = NULL, ...)
## S3 method for class 'character'
h5Attr(x, which, name = NULL, ...)
## S3 method for class 'H5D'
h5AttrNames(x, ...)
## S3 method for class 'H5Group'
h5AttrNames(x, name = NULL, ...)
## S3 method for class 'H5File'
h5AttrNames(x, name = NULL, ...)
## S3 method for class 'character'
h5AttrNames(x, name = NULL, ...)
## S3 method for class 'H5D'
h5Attributes(x, ...)
## S3 method for class 'H5Group'
h5Attributes(x, name = NULL, ...)
## S3 method for class 'H5File'
h5Attributes(x, name = NULL, ...)
## S3 method for class 'character'
h5Attributes(x, name = NULL, ...)
## S3 method for class 'H5D'
h5WriteAttr(
x,
which,
robj,
overwrite = TRUE,
check.scalar = TRUE,
stype = c("utf8", "ascii7"),
...
)
## S3 method for class 'H5Group'
h5WriteAttr(
x,
which,
robj,
name = NULL,
overwrite = TRUE,
check.scalar = TRUE,
stype = c("utf8", "ascii7"),
...
)
## S3 method for class 'H5File'
h5WriteAttr(
x,
which,
robj,
name = NULL,
overwrite = TRUE,
check.scalar = TRUE,
stype = c("utf8", "ascii7"),
...
)
## S3 method for class 'character'
h5WriteAttr(
x,
which,
robj,
name = NULL,
overwrite = TRUE,
check.scalar = TRUE,
stype = c("utf8", "ascii7"),
...
)
## S3 method for class 'H5D'
h5DeleteAttr(x, which, ...)
## S3 method for class 'H5Group'
h5DeleteAttr(x, which, name = NULL, ...)
## S3 method for class 'H5File'
h5DeleteAttr(x, which, name = NULL, ...)
## S3 method for class 'character'
h5DeleteAttr(x, which, name = NULL, ...)
Arguments
x |
|
which |
Name of the HDF5 attribute |
... |
Arguments passed to other methods. |
robj |
An R object to be written as HDF5 attribute |
name |
Name of an existing HDF5 sub-link. Default is NULL, which will use current link. |
overwrite |
Whether or not to overwrite the existing HDF5 attribute. |
check.scalar |
Whether or not to use scalar space when |
stype |
Passed to |
Value
H5Attr
:
If
which
exists in linkname
, will return an R object representing the attribute. Ifwhich
doesn't exist or contains empty data, will returnNULL
.If
name
doesn't exist, will raise an error fromH5File$attr_exists_by_name()
.
h5AttrNames
will return a character vector containing all attribute
names for the given link.
h5Attributes
will return a list containing all attributes for the
given link.
Examples
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra")
# Read H5 attribute
x <- h5Attr(file, "encoding-version")
x <- h5Attr(file, "column-order", "raw/var") ## An empty attribute
stopifnot(length(x) == 0)
h5obj <- h5Open(file, "raw/var", mode = "r")
x <- h5Attr(h5obj, "column-order")
# Read H5 attribute names
h5AttrNames(file)
h5AttrNames(file, "X")
h5AttrNames(h5obj)
# Read all H5 attributes
a1 <- h5Attributes(file, "raw/var")
a2 <- h5Attributes(h5obj)
stopifnot(identical(a1, a2))
# Write H5 attribute
tmp.file <- tempfile(fileext = ".h5")
file.copy(file, tmp.file)
new_a <- character() # Can write an empty attribute
h5WriteAttr(tmp.file, "new_a", robj = new_a, name = "X")
new_a <- c("a", "b")
h5WriteAttr(tmp.file, "new_a", robj = new_a, name = "X", overwrite = TRUE)
h5Attr(tmp.file, "new_a", name = "X")
# Delete H5 attribute
h5DeleteAttr(tmp.file, "new_a", name = "X")
stopifnot(length(h5Attr(tmp.file, "new_a", name = "X")) == 0)