h5WriteScalar {hdf5r.Extra}R Documentation

Write a scalar into HDF5 file

Description

Low-level helper function to write scalar R data into HDF5 dataset. Data will be written into scalar space instead of array space.

Usage

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, ...)

Arguments

x

An H5File, H5Group or a path name of HDF5 file.

name

Name of an HDF5 link.

robj

A scalar object.

...

Arguments passed to H5File$create_dataset(). See link[hdf5r:H5File-class]{H5File}.

stype

'utf8' or 'ascii7'. Passed to h5GuessDtype.

overwrite

Whether or not to overwrite the existing name.

Value

This is an operation function and no return. Any failure should raise an error.

Note

If you want to write robj into array space, you should use h5WriteDataset.

Examples

tmp.file <- tempfile(fileext = ".h5")
h5CreateFile(tmp.file)

h5WriteScalar(tmp.file,  name = "test/scalar", TRUE)
x <- h5ReadDataset(tmp.file, name = "test/scalar")
stopifnot(x)

h5WriteScalar(tmp.file,  name = "test/scalar", 100.0, overwrite = TRUE)
x <- h5ReadDataset(tmp.file, name = "test/scalar")
stopifnot(identical(x, 100.0))

h5WriteScalar(tmp.file,  name = "test/scalar", "ABC", overwrite = TRUE)
x <- h5Read(tmp.file, name = "test/scalar")
stopifnot(identical(x, "ABC"))

h5WriteScalar(tmp.file,  name = "test/factor", factor("ABC"))
x <- h5ReadDataset(tmp.file, name = "test/factor")
stopifnot(identical(x, factor("ABC")))


[Package hdf5r.Extra version 0.0.6 Index]