I want to be able to save an R TRUE/FALSE value in HDF5 such that when reading the file into Python and checking the data type is Boolean the test will pass. At the moment I can't do this. If I use:
library(rhdf5)
h5file = H5Fcreate("newfile.h5")
h5space = H5Screate_simple(1,NULL, native = TRUE)
h5dataset1 = H5Dcreate(h5file, "dataset1", "H5T_NATIVE_HBOOL", h5space)
H5Dwrite(h5dataset1, TRUE)
h5closeAll()
If I then inspect the variable using HDFView (3.1.3) I can see the saved object is stored as an 8-bit unsigned integer.
In order to pass a Python data type test along the lines of np.array(getattr(x,attr)).dtype == bool the type needs to register in HDFView as follows: 8-bit enum (0=FALSE, 1=TRUE).
How can I write an object of this type using either of the two R HDF5 packages rhdf5 or hdf5r?
You may want to explore a third option/package which is HDFql. To create an 8 bit enum dataset named
dataset1containing two members (FALSEwith value0andTRUEwith value1) it can be done as follows using HDFql in R:For additional information, please check HDFql reference manual and examples on how it works.