| Title: | Extensions for 'HDF5' R Interfaces |
|---|---|
| Description: | Some methods to manipulate 'HDF5' files, extending the 'hdf5r' package. Reading and writing R objects to 'HDF5' formats follow the specification of 'AnnData' <https://anndata.readthedocs.io/en/latest/fileformat-prose.html>. |
| Authors: | Yuchen Li [aut, cre] |
| Maintainer: | Yuchen Li <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-17 06:09:28 UTC |
| Source: | https://github.com/ycli1995/hdf5r.extra |
Functions to get, set or delete HDF5 attributes for an existing link.
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, ...)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, ...)
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 |
H5Attr:
If which exists in link name, will return an R object
representing the attribute. If which doesn't exist or contains empty
data, will return NULL.
If name doesn't exist, will raise an error from
H5File$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.
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 length(x) 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) 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") h5Attr(tmp.file, "new_a", name = "X")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 length(x) 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) 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") h5Attr(tmp.file, "new_a", name = "X")
Functions to get the information from an HDF5 dataset.
h5Dims(x, ...) h5MaxDims(x, ...) ## S3 method for class 'H5D' h5Dims(x, ...) ## S3 method for class 'H5Group' h5Dims(x, name, ...) ## S3 method for class 'H5File' h5Dims(x, name, ...) ## S3 method for class 'character' h5Dims(x, name, ...) ## S3 method for class 'H5D' h5MaxDims(x, ...) ## S3 method for class 'H5D' h5MaxDims(x, ...) ## S3 method for class 'H5Group' h5MaxDims(x, name, ...) ## S3 method for class 'H5File' h5MaxDims(x, name, ...) ## S3 method for class 'character' h5MaxDims(x, name, ...)h5Dims(x, ...) h5MaxDims(x, ...) ## S3 method for class 'H5D' h5Dims(x, ...) ## S3 method for class 'H5Group' h5Dims(x, name, ...) ## S3 method for class 'H5File' h5Dims(x, name, ...) ## S3 method for class 'character' h5Dims(x, name, ...) ## S3 method for class 'H5D' h5MaxDims(x, ...) ## S3 method for class 'H5D' h5MaxDims(x, ...) ## S3 method for class 'H5Group' h5MaxDims(x, name, ...) ## S3 method for class 'H5File' h5MaxDims(x, name, ...) ## S3 method for class 'character' h5MaxDims(x, name, ...)
x |
|
... |
Arguments passed to other methods. |
name |
A link in |
h5Dims returns the dimension of the HDF5 dataset.
h5MaxDims returns the maximal dimension of the HDF5 dataset.
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5obj <- h5Open(file, "X", mode = "r") h5Dims(file, "X") h5Dims(h5obj) h5MaxDims(file, "X") h5MaxDims(h5obj)file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5obj <- h5Open(file, "X", mode = "r") h5Dims(file, "X") h5Dims(h5obj) h5MaxDims(file, "X") h5MaxDims(h5obj)
Format an absolute path name for HDF5 link
h5AbsLinkName(name)h5AbsLinkName(name)
name |
String representing an expected name of HDF5 link. |
If name contains any of "", NA or NULL, will simply
return "/".
An update name starting with '/'.
h5AbsLinkName("ggg") h5AbsLinkName("ggg/ddd") h5AbsLinkName(NA) h5AbsLinkName("") h5AbsLinkName(NULL)h5AbsLinkName("ggg") h5AbsLinkName("ggg/ddd") h5AbsLinkName(NA) h5AbsLinkName("") h5AbsLinkName(NULL)
Function to back up HDF5 file, with optionally excluding specific links.
h5Backup( from.file, to.file = NULL, exclude = NULL, overwrite = FALSE, verbose = TRUE, ... )h5Backup( from.file, to.file = NULL, exclude = NULL, overwrite = FALSE, verbose = TRUE, ... )
from.file |
The source HDF5 file. |
to.file |
The target HDF5 file. Cannot be the same file as
|
exclude |
Names of HDF5 links not to be backed up. |
overwrite |
When the |
verbose |
Print progress. |
... |
Arguments passed to |
When any HDF5 link is to be excluded, it will copy the rest of links from
from.file using h5Copy. Otherwise, it will simply copy
the from.file to the to.file via file.copy
Path of the to.file
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") to.file <- tempfile(fileext = ".h5") h5Backup(file, to.file, exclude = "X") x <- h5Read(file) x2 <- h5Read(to.file) x$X <- NULL # Remove 'X' identical(x, x2) # Now these two should be identicalfile <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") to.file <- tempfile(fileext = ".h5") h5Backup(file, to.file, exclude = "X") x <- h5Read(file) x2 <- h5Read(to.file) x$X <- NULL # Remove 'X' identical(x, x2) # Now these two should be identical
Functions to get or check the class of an HDF5 link.
h5Class(file, name) is.H5D(file, name) is.H5Group(file, name)h5Class(file, name) is.H5D(file, name) is.H5Group(file, name)
file |
An existing HDF5 file |
name |
Name of a link in |
h5Class returns a character specifying the class of the query HDF5
link (typically H5D, H5Group or H5File).
is.H5D and is.H5Group return a logical value.
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5Class(file, "X") h5Class(file, "obs") is.H5D(file, "X") is.H5Group(file, "obs")file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5Class(file, "X") h5Class(file, "obs") is.H5D(file, "X") is.H5Group(file, "obs")
Copy an HDF5 link from one file to another file.
h5Copy( from.file, from.name, to.file, to.name, overwrite = FALSE, verbose = TRUE, ... )h5Copy( from.file, from.name, to.file, to.name, overwrite = FALSE, verbose = TRUE, ... )
from.file |
The source HDF5 file. |
from.name |
The source link name. |
to.file |
The target HDF5 file. |
to.name |
The destination HDF5 link name. |
overwrite |
Whether or not to overwrite the existing link. |
verbose |
Print progress. |
... |
Arguments passed to |
This is an operation function and no return. Any failure should raise an error.
Copying can still work even if the to.file is actually identical
to the from.file.
Attributes of from.name will be kept, while those of its parent
H5Groups will not.
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") to.file <- tempfile(fileext = ".h5") # Copy a link to a new file h5Copy(file, "obs", to.file, "obs") obs <- h5Read(file, "obs") obs2 <- h5Read(to.file, "obs") # The parent link (H5Group) will be created automatically h5Copy(file, "obsm/tsne", to.file, "obsm/tsne") obsm <- h5Read(to.file, "obsm") # Copy the whole file x <- h5Read(file) h5Copy(file, "/", to.file, "/", overwrite = TRUE) x2 <- h5Read(to.file)file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") to.file <- tempfile(fileext = ".h5") # Copy a link to a new file h5Copy(file, "obs", to.file, "obs") obs <- h5Read(file, "obs") obs2 <- h5Read(to.file, "obs") # The parent link (H5Group) will be created automatically h5Copy(file, "obsm/tsne", to.file, "obsm/tsne") obsm <- h5Read(to.file, "obsm") # Copy the whole file x <- h5Read(file) h5Copy(file, "/", to.file, "/", overwrite = TRUE) x2 <- h5Read(to.file)
Create a new empty HDF5 dataset
h5CreateDataset(x, name, ...) ## S3 method for class 'H5Group' h5CreateDataset( x, name, dims, dtype = NULL, storage.mode = numeric(), stype = c("utf8", "ascii7"), maxdims = NULL, chunk_size = "auto", gzip_level = 6, ... ) ## S3 method for class 'H5File' h5CreateDataset( x, name, dims, dtype = NULL, storage.mode = numeric(), stype = c("utf8", "ascii7"), maxdims = NULL, chunk_size = "auto", gzip_level = 6, ... ) ## S3 method for class 'character' h5CreateDataset( x, name, dims, dtype = NULL, storage.mode = numeric(), stype = c("utf8", "ascii7"), maxdims = NULL, overwrite = FALSE, chunk_size = "auto", gzip_level = 6, ... )h5CreateDataset(x, name, ...) ## S3 method for class 'H5Group' h5CreateDataset( x, name, dims, dtype = NULL, storage.mode = numeric(), stype = c("utf8", "ascii7"), maxdims = NULL, chunk_size = "auto", gzip_level = 6, ... ) ## S3 method for class 'H5File' h5CreateDataset( x, name, dims, dtype = NULL, storage.mode = numeric(), stype = c("utf8", "ascii7"), maxdims = NULL, chunk_size = "auto", gzip_level = 6, ... ) ## S3 method for class 'character' h5CreateDataset( x, name, dims, dtype = NULL, storage.mode = numeric(), stype = c("utf8", "ascii7"), maxdims = NULL, overwrite = FALSE, chunk_size = "auto", gzip_level = 6, ... )
x |
|
name |
Name of the new HDF5 dataset. |
... |
Arguments passed to |
dims |
Dimensions of the new dataset. |
dtype |
The H5 datatype to use for the creation of the object. Must be
an |
storage.mode |
Object used to guess the HDF5 datatype. Default is
|
stype |
'utf8' or 'ascii7'. Passed to |
maxdims |
The maximal dimensions of the space. Default is |
chunk_size |
Size of the chunk. Must have the same length as the dataset
dimension. If |
gzip_level |
Enable zipping at the level given here. Only if chunk_dims
is not |
overwrite |
Whether or not to overwrite the existing HDF5 dataset. |
This is an operation function and no return. Any failure should raise an error.
H5File and H5Group for the
$create_dataset() methods.
tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) m <- matrix(0, 10, 5) h5CreateDataset(tmp.file, "g1/m", dim(m)) m2 <- c("a", "b", "c") h5CreateDataset(tmp.file, "g2/m2", length(m2), storage.mode = m2)tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) m <- matrix(0, 10, 5) h5CreateDataset(tmp.file, "g1/m", dim(m)) m2 <- c("a", "b", "c") h5CreateDataset(tmp.file, "g2/m2", length(m2), storage.mode = m2)
A wrapper for H5File$new(). If file
exists, will only raise a warning.
h5CreateFile(x, ...) ## S3 method for class 'character' h5CreateFile(x, ...)h5CreateFile(x, ...) ## S3 method for class 'character' h5CreateFile(x, ...)
x |
Name of the new HDF5 file. |
... |
Arguments passed to |
This is an operation function and no return. Any failure should raise an error.
tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file)tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file)
Create new HDF5 group
h5CreateGroup(x, name, ...) ## S3 method for class 'H5Group' h5CreateGroup(x, name, show.warnings = TRUE, ...) ## S3 method for class 'H5File' h5CreateGroup(x, name, show.warnings = TRUE, ...) ## S3 method for class 'character' h5CreateGroup(x, name, show.warnings = TRUE, ...)h5CreateGroup(x, name, ...) ## S3 method for class 'H5Group' h5CreateGroup(x, name, show.warnings = TRUE, ...) ## S3 method for class 'H5File' h5CreateGroup(x, name, show.warnings = TRUE, ...) ## S3 method for class 'character' h5CreateGroup(x, name, show.warnings = TRUE, ...)
x |
|
name |
Name of the new HDF5 group. Can be recursive, such as "g/sub_g". |
... |
Arguments passed to |
show.warnings |
When the group |
This is an operation function and no return. Any failure should raise an error.
tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) h5CreateGroup(tmp.file, "g1") h5CreateGroup(tmp.file, "g2/g3")tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) h5CreateGroup(tmp.file, "g1") h5CreateGroup(tmp.file, "g2/g3")
Delete an HDF5 link
h5Delete(x, name, ...) ## S3 method for class 'H5Group' h5Delete(x, name, verbose = TRUE, ...) ## S3 method for class 'H5File' h5Delete(x, name, verbose = TRUE, ...) ## S3 method for class 'character' h5Delete(x, name, verbose = TRUE, ...)h5Delete(x, name, ...) ## S3 method for class 'H5Group' h5Delete(x, name, verbose = TRUE, ...) ## S3 method for class 'H5File' h5Delete(x, name, verbose = TRUE, ...) ## S3 method for class 'character' h5Delete(x, name, verbose = TRUE, ...)
x |
An existing HDF5 file |
name |
Name of HDF5 link to be deleted. If |
... |
Arguments passed to |
verbose |
Print progress. |
This is an operation function and no return. Any failure should raise an error.
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") to.file <- tempfile(fileext = ".h5") file.copy(file, to.file) h5Delete(to.file, "obs") h5Delete(to.file, "xxxx") # Delete something not existing.file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") to.file <- tempfile(fileext = ".h5") file.copy(file, to.file) h5Delete(to.file, "obs") h5Delete(to.file, "xxxx") # Delete something not existing.
Check existence of an HDF5 link
h5Exists(x, name, ...) ## S3 method for class 'H5Group' h5Exists(x, name, ...) ## S3 method for class 'H5File' h5Exists(x, name, ...) ## S3 method for class 'character' h5Exists(x, name, ...)h5Exists(x, name, ...) ## S3 method for class 'H5Group' h5Exists(x, name, ...) ## S3 method for class 'H5File' h5Exists(x, name, ...) ## S3 method for class 'character' h5Exists(x, name, ...)
x |
|
name |
Name of HDF5 link to be checked. |
... |
Arguments passed to |
If any parent directory of name doesn't exist, will simply
return FALSE
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5Exists(file, "/") h5Exists(file, "obs") h5Exists(file, "X") h5fh <- h5TryOpen(file, mode = "r") h5Exists(h5fh, "obs") h5obj <- h5Open(h5fh, "obs") h5Exists(h5obj, "groups")file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5Exists(file, "/") h5Exists(file, "obs") h5Exists(file, "X") h5fh <- h5TryOpen(file, mode = "r") h5Exists(h5fh, "obs") h5obj <- h5Open(h5fh, "obs") h5Exists(h5obj, "groups")
Wrapper around hdf5r::guess_dtype, allowing
for the customization of string types such as utf-8 rather than defaulting to
variable-length ASCII-encoded strings.
h5GuessDtype(x, stype = c("utf8", "ascii7"), ...)h5GuessDtype(x, stype = c("utf8", "ascii7"), ...)
x |
The object for which to guess the HDF5 datatype |
stype |
'utf8' or 'ascii7' |
... |
Arguments passed to |
An object of class H5T
https://github.com/mojaveazure/seurat-disk/blob/163f1aade5bac38ed1e9e9c912283a7e74781610/R/zzz.R
h5GuessDtype(0) h5GuessDtype("abc")h5GuessDtype(0) h5GuessDtype("abc")
Function to list the contents of an HDF5 group.
h5List(x, ...) ## S3 method for class 'H5Group' h5List( x, recursive = FALSE, full.names = FALSE, simplify = TRUE, detailed = FALSE, ... ) ## S3 method for class 'H5File' h5List( x, name = "/", recursive = FALSE, full.names = FALSE, simplify = TRUE, detailed = FALSE, ... ) ## S3 method for class 'character' h5List( x, name = "/", recursive = FALSE, full.names = FALSE, simplify = TRUE, detailed = FALSE, ... )h5List(x, ...) ## S3 method for class 'H5Group' h5List( x, recursive = FALSE, full.names = FALSE, simplify = TRUE, detailed = FALSE, ... ) ## S3 method for class 'H5File' h5List( x, name = "/", recursive = FALSE, full.names = FALSE, simplify = TRUE, detailed = FALSE, ... ) ## S3 method for class 'character' h5List( x, name = "/", recursive = FALSE, full.names = FALSE, simplify = TRUE, detailed = FALSE, ... )
x |
|
... |
Additional parameters passed to |
recursive |
If TRUE, the contents of the whole group hierarchy will be listed. |
full.names |
Whether or not to return the absolute object path names. |
simplify |
Whether or not to only return the object names. |
detailed |
Whether or not to show the detailed information. |
name |
A link in file. Must refer to an H5Group. Default is "/". |
If simplify, will return a character vector specifying names of H5
links, otherwise will return a data.frame to show details.
H5Group$ls()
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5List(file) h5List(file, "obs") h5List(file, recursive = TRUE) h5List(file, "obs", simplify = FALSE, recursive = TRUE) h5g <- h5Open(file, "obs", mode = "r") h5List(h5g)file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5List(file) h5List(file, "obs") h5List(file, recursive = TRUE) h5List(file, "obs", simplify = FALSE, recursive = TRUE) h5g <- h5Open(file, "obs", mode = "r") h5List(h5g)
Move one HDF5 link to another position within the same file.
h5Move(file, from.name, to.name, overwrite = FALSE, verbose = TRUE, ...)h5Move(file, from.name, to.name, overwrite = FALSE, verbose = TRUE, ...)
file |
An HDF5 file. |
from.name |
Name of the source link. |
to.name |
Name of the destination link. |
overwrite |
When |
verbose |
Print progress. |
... |
Arguments passed to |
This is an operation function and no return. Any failure should raise an error.
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") to.file <- tempfile(fileext = ".h5") file.copy(file, to.file) obs <- h5Read(to.file, "obs") h5Move(to.file, "obs", "obs2") obs2 <- h5Read(to.file, "obs2") # Move an object to an existing link h5Move(to.file, "obs2", "var") # Warning h5Move(to.file, "obs2", "var", overwrite = TRUE) # Move a non-existing object will raise an error try(h5Move(to.file, "obs", "obs3"))file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") to.file <- tempfile(fileext = ".h5") file.copy(file, to.file) obs <- h5Read(to.file, "obs") h5Move(to.file, "obs", "obs2") obs2 <- h5Read(to.file, "obs2") # Move an object to an existing link h5Move(to.file, "obs2", "var") # Warning h5Move(to.file, "obs2", "var", overwrite = TRUE) # Move a non-existing object will raise an error try(h5Move(to.file, "obs", "obs3"))
Open an HDF5 file, file-handler or group object
h5Open(x, name, ...) ## S3 method for class 'H5Group' h5Open(x, name, ...) ## S3 method for class 'H5File' h5Open(x, name, ...) ## S3 method for class 'character' h5Open(x, name, mode = c("a", "r", "r+", "w", "w-", "x"), ...)h5Open(x, name, ...) ## S3 method for class 'H5Group' h5Open(x, name, ...) ## S3 method for class 'H5File' h5Open(x, name, ...) ## S3 method for class 'character' h5Open(x, name, mode = c("a", "r", "r+", "w", "w-", "x"), ...)
x |
|
name |
Name of the opened HDF5 link. |
... |
Arguments passed to #' @details
For an |
mode |
Passed to |
An opened H5File, H5Group
or H5D.
When x is an H5File or a file path,
name = "/" should always return an H5File.
When x is an H5Group, name = "/"
should raise an error.
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") obs <- h5Open(file, "obs", mode = "r") inherits(obs, "H5Group") h5fh <- h5Open(file, "/", mode = "r") inherits(h5fh, "H5File") tsne <- h5Open(file, "obsm/tsne", mode = "r") inherits(tsne, "H5D") try(h5Open(obs, "/")) ## Errorfile <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") obs <- h5Open(file, "obs", mode = "r") inherits(obs, "H5Group") h5fh <- h5Open(file, "/", mode = "r") inherits(h5fh, "H5File") tsne <- h5Open(file, "obsm/tsne", mode = "r") inherits(tsne, "H5D") try(h5Open(obs, "/")) ## Error
Overwrite an existing HDF5 link
h5Overwrite( file, name, overwrite, verbose = getOption(x = "h5.overwrite.verbose", default = FALSE) )h5Overwrite( file, name, overwrite, verbose = getOption(x = "h5.overwrite.verbose", default = FALSE) )
file |
An existing HDF5 file |
name |
Name of HDF5 link to be overwritten. |
overwrite |
Whether or not to overwrite |
verbose |
Print progress. |
When file doesn't exist, will create it.
When the old link name doesn't exist, will simply return
file.
When name exists and overwrite is TRUE, will copy
the rest of HDF5 links to an updated file with h5Backup.
If name is "/", will create a new file and overwrite the old one.
When name exists and overwrite is FALSE, will
raise an error.
Path to file which is ready to be written.
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") tmp.file <- tempfile(fileext = ".h5") file.copy(file, tmp.file) obs <- h5Read(tmp.file, "obs") h5Overwrite(tmp.file, "layers", TRUE) h5Exists(tmp.file, "layers") # You can still read other links. obs2 <- h5Read(tmp.file, "obs") identical(obs, obs2)file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") tmp.file <- tempfile(fileext = ".h5") file.copy(file, tmp.file) obs <- h5Read(tmp.file, "obs") h5Overwrite(tmp.file, "layers", TRUE) h5Exists(tmp.file, "layers") # You can still read other links. obs2 <- h5Read(tmp.file, "obs") identical(obs, obs2)
Methods to transform a complex R object (for example, S4 object) into
combination of base R objects, such as vector, array,
data.frame or list, so that it can be written into HDF5 file.
h5Prep(x, ...) ## Default S3 method: h5Prep(x, ...)h5Prep(x, ...) ## Default S3 method: h5Prep(x, ...)
x |
The R object to be transformed |
... |
Arguments to be passed to other methods |
In this package, h5Prep will return x itself by default.
Extended methods can be easily added for specific S4 class.
An R object of converted x.
Function to read data from an existing HDF5 group.
h5Read(x, name = NULL, ...) ## S3 method for class 'H5Group' h5Read(x, name = NULL, transpose = FALSE, ...) ## S3 method for class 'H5File' h5Read(x, name = NULL, transpose = FALSE, ...) ## S3 method for class 'character' h5Read(x, name = NULL, transpose = FALSE, ...)h5Read(x, name = NULL, ...) ## S3 method for class 'H5Group' h5Read(x, name = NULL, transpose = FALSE, ...) ## S3 method for class 'H5File' h5Read(x, name = NULL, transpose = FALSE, ...) ## S3 method for class 'character' h5Read(x, name = NULL, transpose = FALSE, ...)
x |
|
name |
Name of the HDF5 link to be read. |
... |
Arguments passed to |
transpose |
Whether or not to transpose the read matrix. Only works for a 2-dimension array-like data. |
The load R object. Currently support vector, matrix,
data.frame, list and sparse matrix (dgCMatrix and
dgRMatrix).
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") # Read a matrix x <- h5Read(file, name = "X") x <- h5Read(file, name = "X", transpose = TRUE) x <- h5Read(file, name = "X", idx_list = list(1:10, 1:20)) x <- h5Read( file, name = "X", idx_list = list(1:10, 1:20), transpose = TRUE ) # Read a dgCMatrix x <- h5Read(file, name = "raw/X") x <- h5Read(file, name = "raw/X", transpose = TRUE) # Read a data.frame x <- h5Read(file, name = "obs") x <- h5Read(file, name = "raw/var") # Read a data.frame with empty column # Read a list x <- h5Read(file) x <- h5Read(file, "raw") x <- h5Read(file, "obsm")file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") # Read a matrix x <- h5Read(file, name = "X") x <- h5Read(file, name = "X", transpose = TRUE) x <- h5Read(file, name = "X", idx_list = list(1:10, 1:20)) x <- h5Read( file, name = "X", idx_list = list(1:10, 1:20), transpose = TRUE ) # Read a dgCMatrix x <- h5Read(file, name = "raw/X") x <- h5Read(file, name = "raw/X", transpose = TRUE) # Read a data.frame x <- h5Read(file, name = "obs") x <- h5Read(file, name = "raw/var") # Read a data.frame with empty column # Read a list x <- h5Read(file) x <- h5Read(file, "raw") x <- h5Read(file, "obsm")
Low-level helper function to read atomic R data from an existing H5 dataset.
h5ReadDataset(x, ...) ## S3 method for class 'H5D' h5ReadDataset(x, idx_list = NULL, transpose = FALSE, ...) ## S3 method for class 'H5Group' h5ReadDataset(x, name, idx_list = NULL, transpose = FALSE, ...) ## S3 method for class 'H5File' h5ReadDataset(x, name, idx_list = NULL, transpose = FALSE, ...) ## S3 method for class 'character' h5ReadDataset(x, name, transpose = FALSE, idx_list = NULL, ...)h5ReadDataset(x, ...) ## S3 method for class 'H5D' h5ReadDataset(x, idx_list = NULL, transpose = FALSE, ...) ## S3 method for class 'H5Group' h5ReadDataset(x, name, idx_list = NULL, transpose = FALSE, ...) ## S3 method for class 'H5File' h5ReadDataset(x, name, idx_list = NULL, transpose = FALSE, ...) ## S3 method for class 'character' h5ReadDataset(x, name, transpose = FALSE, idx_list = NULL, ...)
x |
|
... |
Arguments passed to |
idx_list |
The indices for each dimension of |
transpose |
Whether or not to transpose the read matrix. Only works for a 2-dimension array-like data. |
name |
Name of the HDF5 link to be read. Must be an H5 dataset. |
An array-like object with the data read.
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") x <- h5ReadDataset(file, name = "X") x <- h5ReadDataset(file, name = "X", transpose = TRUE) x <- h5ReadDataset(file, name = "X", idx_list = list(1:10, 1:20)) x <- h5ReadDataset( file, name = "X", idx_list = list(1:10, 1:20), transpose = TRUE )file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") x <- h5ReadDataset(file, name = "X") x <- h5ReadDataset(file, name = "X", transpose = TRUE) x <- h5ReadDataset(file, name = "X", idx_list = list(1:10, 1:20)) x <- h5ReadDataset( file, name = "X", idx_list = list(1:10, 1:20), transpose = TRUE )
Helper function to open an HDF5 file. When the opening fails, will retry it until reach a timeout.
h5TryOpen( filename, mode = c("a", "r", "r+", "w", "w-", "x"), timeout = getOption(x = "h5TryOpen.timeout", default = 0), interval = getOption(x = "h5TryOpen.interval", default = 0), ... )h5TryOpen( filename, mode = c("a", "r", "r+", "w", "w-", "x"), timeout = getOption(x = "h5TryOpen.timeout", default = 0), interval = getOption(x = "h5TryOpen.interval", default = 0), ... )
filename |
An HDF5 file to open |
mode |
How to open it:
|
timeout |
Positive integer. The timeout for retrying. |
interval |
Positive integer. The interval seconds of retrying. |
... |
Arguments passed to |
timeout and interval must be positive. Otherwise no retrying,
which is default setting.
When file is opened successfully, an H5File will
be returned. Otherwise, will keep retrying. When a timeout is reached, will
raise an error and terminate the current R session.
H5File for mode
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5fh <- h5TryOpen(file, mode = "r") h5fh h5fh$close_all()file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") h5fh <- h5TryOpen(file, mode = "r") h5fh h5fh$close_all()
Methods to write an R object to an HDF5 file.
h5Write(x, file, name, ...) ## Default S3 method: h5Write(x, file, name, overwrite = FALSE, gzip_level = 6, ...) ## S3 method for class 'array' h5Write( x, file, name, overwrite = FALSE, transpose = FALSE, block_size = 5000L, gzip_level = 6, ... ) ## S3 method for class 'factor' h5Write(x, file, name, overwrite = FALSE, ordered = TRUE, gzip_level = 6, ...) ## S3 method for class 'data.frame' h5Write(x, file, name, overwrite = FALSE, gzip_level = 6, ...) ## S3 method for class 'dgCMatrix' h5Write( x, file, name, overwrite = FALSE, transpose = FALSE, add.shape = FALSE, add.dimnames = TRUE, gzip_level = 6, ... ) ## S3 method for class 'dgRMatrix' h5Write( x, file, name, overwrite = FALSE, transpose = FALSE, add.shape = FALSE, add.dimnames = TRUE, gzip_level = 6, ... ) ## S3 method for class 'list' h5Write(x, file, name, overwrite = FALSE, gzip_level = 6, ...)h5Write(x, file, name, ...) ## Default S3 method: h5Write(x, file, name, overwrite = FALSE, gzip_level = 6, ...) ## S3 method for class 'array' h5Write( x, file, name, overwrite = FALSE, transpose = FALSE, block_size = 5000L, gzip_level = 6, ... ) ## S3 method for class 'factor' h5Write(x, file, name, overwrite = FALSE, ordered = TRUE, gzip_level = 6, ...) ## S3 method for class 'data.frame' h5Write(x, file, name, overwrite = FALSE, gzip_level = 6, ...) ## S3 method for class 'dgCMatrix' h5Write( x, file, name, overwrite = FALSE, transpose = FALSE, add.shape = FALSE, add.dimnames = TRUE, gzip_level = 6, ... ) ## S3 method for class 'dgRMatrix' h5Write( x, file, name, overwrite = FALSE, transpose = FALSE, add.shape = FALSE, add.dimnames = TRUE, gzip_level = 6, ... ) ## S3 method for class 'list' h5Write(x, file, name, overwrite = FALSE, gzip_level = 6, ...)
x |
An R object to be written |
file |
An existing HDF5 file |
name |
Name of the HDF5 link to be written into |
... |
Arguments passed to other methods. |
overwrite |
Whether or not to overwrite the existing HDF5 link. |
gzip_level |
Enable zipping at the level given here. |
transpose |
Whether or not to transpose the input matrix. Only works for a 2-dimension array-like object. |
block_size |
Default size for number of columns when |
ordered |
When writing a factor, whether or not the categories are ordered. |
add.shape |
When writing a CSC- or CSR-matrix, whether or not to also write the number of dimensions into an HDF5 dataset. |
add.dimnames |
When writing a CSC- or CSR-matrix, whether or not to also write the dimension names. |
By default, h5Write will try to transform any S4 object x into
combination of base R objects using h5Prep before writting it.
This is an operation function and no return. Any failure should raise an error.
https://anndata.readthedocs.io/en/latest/fileformat-prose.html
file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) # vector ----------------------- x <- h5Read(file, "/raw/X/data") h5Write(x, tmp.file, "raw/X/data") x2 <- h5Read(tmp.file, "raw/X/data") # matrix ----------------------- x <- h5Read(file, "X") h5Write(x, tmp.file, "X") x2 <- h5Read(tmp.file, "X") identical(x, x2) h5Write(x, tmp.file, "X2", transpose = TRUE) x2 <- h5Read(tmp.file, "X2") identical(t(x), x2) # data.frame ----------------------- x <- h5Read(file, "obs") h5Write(x, tmp.file, "obs") x2 <- h5Read(tmp.file, "obs") identical(x, x2) x <- h5Read(file, "raw/var") # data.frame with empty column h5Write(x, tmp.file, "raw/var") x2 <- h5Read(tmp.file, "raw/var") identical(x, x2) # dgCMatrix ----------------------- x <- h5Read(file, "raw/X") h5Write(x, tmp.file, "raw/X", overwrite = TRUE) x2 <- h5Read(tmp.file, "raw/X") identical(x, x2) # list ----------------------- x <- h5Read(file) h5Write(x, tmp.file, name = NULL, overwrite = TRUE) x2 <- h5Read(tmp.file) identical(x, x2)file <- system.file("extdata", "pbmc_small.h5ad", package = "hdf5r.Extra") tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) # vector ----------------------- x <- h5Read(file, "/raw/X/data") h5Write(x, tmp.file, "raw/X/data") x2 <- h5Read(tmp.file, "raw/X/data") # matrix ----------------------- x <- h5Read(file, "X") h5Write(x, tmp.file, "X") x2 <- h5Read(tmp.file, "X") identical(x, x2) h5Write(x, tmp.file, "X2", transpose = TRUE) x2 <- h5Read(tmp.file, "X2") identical(t(x), x2) # data.frame ----------------------- x <- h5Read(file, "obs") h5Write(x, tmp.file, "obs") x2 <- h5Read(tmp.file, "obs") identical(x, x2) x <- h5Read(file, "raw/var") # data.frame with empty column h5Write(x, tmp.file, "raw/var") x2 <- h5Read(tmp.file, "raw/var") identical(x, x2) # dgCMatrix ----------------------- x <- h5Read(file, "raw/X") h5Write(x, tmp.file, "raw/X", overwrite = TRUE) x2 <- h5Read(tmp.file, "raw/X") identical(x, x2) # list ----------------------- x <- h5Read(file) h5Write(x, tmp.file, name = NULL, overwrite = TRUE) x2 <- h5Read(tmp.file) identical(x, x2)
Low-level helper function to write atomic R data into an existing H5 dataset. All data written will be treated as array for HDF5.
h5WriteDataset(x, robj, ...) ## S3 method for class 'H5D' h5WriteDataset( x, robj, idx_list = NULL, transpose = FALSE, block_size = 5000L, verbose = TRUE, ... ) ## S3 method for class 'H5Group' h5WriteDataset( x, robj, name, idx_list = NULL, transpose = FALSE, block_size = 5000L, verbose = TRUE, ... ) ## S3 method for class 'H5File' h5WriteDataset( x, robj, name, idx_list = NULL, transpose = FALSE, block_size = 5000L, verbose = TRUE, ... ) ## S3 method for class 'character' h5WriteDataset( x, robj, name, idx_list = NULL, transpose = FALSE, block_size = 5000L, verbose = TRUE, ... )h5WriteDataset(x, robj, ...) ## S3 method for class 'H5D' h5WriteDataset( x, robj, idx_list = NULL, transpose = FALSE, block_size = 5000L, verbose = TRUE, ... ) ## S3 method for class 'H5Group' h5WriteDataset( x, robj, name, idx_list = NULL, transpose = FALSE, block_size = 5000L, verbose = TRUE, ... ) ## S3 method for class 'H5File' h5WriteDataset( x, robj, name, idx_list = NULL, transpose = FALSE, block_size = 5000L, verbose = TRUE, ... ) ## S3 method for class 'character' h5WriteDataset( x, robj, name, idx_list = NULL, transpose = FALSE, block_size = 5000L, verbose = TRUE, ... )
x |
|
robj |
An R array. |
... |
Arguments passed to |
idx_list |
The indices for each dimension of |
transpose |
Whether or not to transpose the input matrix. Only works for a 2-dimension array-like object. |
block_size |
Default size for number of columns to transpose in a single writing. Increasing block_size may speed up but at an additional memory cost. |
verbose |
Print progress. |
name |
Name of the HDF5 dataset to be written. |
This is an operation function and no return. Any failure should raise an error.
If you want to write robj into scalar space, you should use
h5WriteScalar.
tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) # Scalar (will be written into array space for HDF5) ########## h5CreateDataset( tmp.file, name = "test/bool", dims = 1, storage.mode = logical() ) # Must create the dataset first h5WriteDataset(tmp.file, FALSE, name = "test/bool") x <- h5Read(tmp.file, name = "test/bool") x h5CreateDataset(tmp.file, name = "test/num", dims = 1) h5WriteDataset(tmp.file, 100.0, name = "test/num") x <- h5Read(tmp.file, name = "test/num") x h5CreateDataset( tmp.file, name = "test/string", dims = 1, storage.mode = character() ) h5WriteDataset(tmp.file, "ABC", name = "test/string") x <- h5Read(tmp.file, name = "test/string") x # Vector (1d array) ########## x1 <- rep(FALSE, 10) h5CreateDataset( tmp.file, name = "vec/bool", dims = 10, storage.mode = logical() ) h5WriteDataset(tmp.file, x1, name = "vec/bool") x <- h5Read(tmp.file, name = "vec/bool") x x1 <- rep(1.1, 10) h5CreateDataset( tmp.file, name = "vec/num", dims = 10 ) h5WriteDataset(tmp.file, x1, name = "vec/num") x <- h5Read(tmp.file, name = "vec/num") x x1 <- rep(2.0, 5) h5WriteDataset( tmp.file, x1, name = "vec/num", idx_list = list(c(1, 3, 5, 7, 9)) # Set each indices to be written ) x <- h5Read(tmp.file, name = "vec/num") stopifnot(identical(x, rep(c(2.0, 1.1), 5))) # matrix ########## x1 <- matrix(1.0, 7, 5) h5CreateDataset( tmp.file, name = "mat/num", dims = dim(x1) ) h5WriteDataset( tmp.file, x1, name = "mat/num" ) x <- h5Read(tmp.file, name = "mat/num") x x1 <- matrix(2.0, 3, 4) h5WriteDataset( tmp.file, x1, name = "mat/num", idx_list = list(2:4, 1:4) ) x <- h5Read(tmp.file, name = "mat/num") print(x) h5WriteDataset( tmp.file, x1, name = "mat/num", idx_list = list(1:4, 2:4), # idx_list must match the transposed matrix transpose = TRUE ) x <- h5Read(tmp.file, name = "mat/num") print(x)tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) # Scalar (will be written into array space for HDF5) ########## h5CreateDataset( tmp.file, name = "test/bool", dims = 1, storage.mode = logical() ) # Must create the dataset first h5WriteDataset(tmp.file, FALSE, name = "test/bool") x <- h5Read(tmp.file, name = "test/bool") x h5CreateDataset(tmp.file, name = "test/num", dims = 1) h5WriteDataset(tmp.file, 100.0, name = "test/num") x <- h5Read(tmp.file, name = "test/num") x h5CreateDataset( tmp.file, name = "test/string", dims = 1, storage.mode = character() ) h5WriteDataset(tmp.file, "ABC", name = "test/string") x <- h5Read(tmp.file, name = "test/string") x # Vector (1d array) ########## x1 <- rep(FALSE, 10) h5CreateDataset( tmp.file, name = "vec/bool", dims = 10, storage.mode = logical() ) h5WriteDataset(tmp.file, x1, name = "vec/bool") x <- h5Read(tmp.file, name = "vec/bool") x x1 <- rep(1.1, 10) h5CreateDataset( tmp.file, name = "vec/num", dims = 10 ) h5WriteDataset(tmp.file, x1, name = "vec/num") x <- h5Read(tmp.file, name = "vec/num") x x1 <- rep(2.0, 5) h5WriteDataset( tmp.file, x1, name = "vec/num", idx_list = list(c(1, 3, 5, 7, 9)) # Set each indices to be written ) x <- h5Read(tmp.file, name = "vec/num") stopifnot(identical(x, rep(c(2.0, 1.1), 5))) # matrix ########## x1 <- matrix(1.0, 7, 5) h5CreateDataset( tmp.file, name = "mat/num", dims = dim(x1) ) h5WriteDataset( tmp.file, x1, name = "mat/num" ) x <- h5Read(tmp.file, name = "mat/num") x x1 <- matrix(2.0, 3, 4) h5WriteDataset( tmp.file, x1, name = "mat/num", idx_list = list(2:4, 1:4) ) x <- h5Read(tmp.file, name = "mat/num") print(x) h5WriteDataset( tmp.file, x1, name = "mat/num", idx_list = list(1:4, 2:4), # idx_list must match the transposed matrix transpose = TRUE ) x <- h5Read(tmp.file, name = "mat/num") print(x)
Low-level helper function to write scalar R data into HDF5 dataset. Data will be written into scalar space instead of array space.
h5WriteScalar(x, name, robj, ...) ## S3 method for class 'H5Group' h5WriteScalar(x, name, robj, stype = c("utf8", "ascii7"), ...) ## S3 method for class 'H5File' h5WriteScalar(x, name, robj, ...) ## S3 method for class 'character' h5WriteScalar(x, name, robj, overwrite = FALSE, ...)h5WriteScalar(x, name, robj, ...) ## S3 method for class 'H5Group' h5WriteScalar(x, name, robj, stype = c("utf8", "ascii7"), ...) ## S3 method for class 'H5File' h5WriteScalar(x, name, robj, ...) ## S3 method for class 'character' h5WriteScalar(x, name, robj, overwrite = FALSE, ...)
x |
|
name |
Name of an HDF5 link. |
robj |
A scalar object. |
... |
Arguments passed to |
stype |
'utf8' or 'ascii7'. Passed to |
overwrite |
Whether or not to overwrite the existing |
This is an operation function and no return. Any failure should raise an error.
If you want to write robj into array space, you should use
h5WriteDataset.
tmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) h5WriteScalar(tmp.file, name = "test/scalar", TRUE) x <- h5ReadDataset(tmp.file, name = "test/scalar") x h5WriteScalar(tmp.file, name = "test/scalar", 100.0, overwrite = TRUE) x <- h5ReadDataset(tmp.file, name = "test/scalar") x h5WriteScalar(tmp.file, name = "test/scalar", "ABC", overwrite = TRUE) x <- h5Read(tmp.file, name = "test/scalar") x h5WriteScalar(tmp.file, name = "test/factor", factor("ABC")) x <- h5ReadDataset(tmp.file, name = "test/factor") xtmp.file <- tempfile(fileext = ".h5") h5CreateFile(tmp.file) h5WriteScalar(tmp.file, name = "test/scalar", TRUE) x <- h5ReadDataset(tmp.file, name = "test/scalar") x h5WriteScalar(tmp.file, name = "test/scalar", 100.0, overwrite = TRUE) x <- h5ReadDataset(tmp.file, name = "test/scalar") x h5WriteScalar(tmp.file, name = "test/scalar", "ABC", overwrite = TRUE) x <- h5Read(tmp.file, name = "test/scalar") x h5WriteScalar(tmp.file, name = "test/factor", factor("ABC")) x <- h5ReadDataset(tmp.file, name = "test/factor") x