Inspects an HDF5 object and returns the R class that h5_read() would produce.
Value
A character string representing the R class (e.g., "numeric", "complex",
"character", "factor", "raw", "list", "NULL").
Returns NA_character_ for HDF5 types that h5lite cannot read.
Details
This function determines the resulting R class by inspecting the object's metadata.
Groups are reported as
"list".Datasets (integers, floats) are reported as
"numeric"(sinceh5_readalways returnsdouble).String datasets are reported as
"character".Complex datasets are reported as
"complex".Enum datasets are reported as
"factor".1-byte Opaque datasets are reported as
"raw".Compound datasets are reported as
"data.frame".Null datasets (with a null dataspace) are reported as
"NULL".
If attrs is set to TRUE or is a character vector containing "class",
this function will first check for an HDF5 attribute on the object named
"class". If a string attribute with this name exists, its value
(e.g., "data.frame") will be returned, taking precedence over
the object's type.
Examples
file <- tempfile(fileext = ".h5")
# Write various object types
h5_write(file, "integers", 1:5)
h5_write(file, "doubles", c(1.1, 2.2))
h5_write(file, "text", "hello")
h5_create_group(file, "my_group")
# Write a data.frame, which becomes a compound dataset
h5_write(file, "my_df", data.frame(a = 1:2, b = c("x", "y")))
# Check R classes
h5_class(file, "integers") # "numeric"
#> [1] "numeric"
h5_class(file, "doubles") # "numeric"
#> [1] "numeric"
h5_class(file, "text") # "character"
#> [1] "character"
h5_class(file, "my_group") # "list"
#> [1] "list"
# Check the data.frame
h5_class(file, "my_df") # "data.frame"
#> [1] "data.frame"
h5_class(file, "my_df", attrs = TRUE) # "data.frame"
#> [1] "data.frame"
unlink(file)
