Learn R Programming

h5lite (version 2.0.0.2)

h5_class: Get R Class of an HDF5 Object or Attribute

Description

Inspects an HDF5 object (or an attribute attached to it) and returns the R class that h5_read() would produce.

Usage

h5_class(file, name, attr = NULL)

Value

A character string representing the R class (e.g., "integer", "numeric", "complex", "character", "factor", "raw", "list", "NULL"). Returns NA_character_ for HDF5 types that h5lite cannot read.

Arguments

file

The path to the HDF5 file.

name

The full path of the object (group or dataset) to check.

attr

The name of an attribute to check. If NULL (default), the function checks the class of the object itself.

Details

This function determines the resulting R class by inspecting the storage metadata.

  • Group \(\rightarrow\) "list"

  • Integer \(\rightarrow\) "numeric"

  • Floating Point \(\rightarrow\) "numeric"

  • String \(\rightarrow\) "character"

  • Complex \(\rightarrow\) "complex"

  • Enum \(\rightarrow\) "factor"

  • Opaque \(\rightarrow\) "raw"

  • Compound \(\rightarrow\) "data.frame"

  • Null \(\rightarrow\) "NULL"

See Also

h5_typeof(), h5_read()

Examples

Run this code
file <- tempfile(fileext = ".h5")

h5_write(1:10, file, "my_ints", as = "int32")
h5_class(file, "my_ints") # "numeric"

h5_write(mtcars, file, "mtcars")
h5_class(file, "mtcars") # "data.frame"

h5_write(c("a", "b", "c"), file, "strings")
h5_class(file, "strings") # "character"

h5_write(c(1, 2, 3), file, "my_floats", as = "float64")
h5_class(file, "my_floats") # "numeric"

unlink(file)

Run the code above in your browser using DataLab