Search
0
17 months ago by
United States
Kipper Fletez-Brant150 wrote:

Hi,

I'm trying to create an HDF5 file using the rhdf5 library.  However, it seems that either I cannot create general attributes for the file, or there is some confusion about what I am doing, as rhdf5 both can and cannot generate the attribute.  Here is a minimal example:

tmp <- "tmp.hdf5"

tmp <- H5Fcreate(tmp)

h5writeAttribute(attr=matrix(1), h5obj=tmp, name="nchroms")

Object nchroms does not exist in this HDF5 file.

H5Aexists(tmp, "nchroms")
[1] TRUE

What is going on here?

sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin16.3.0 (64-bit)
Running under: macOS Sierra 10.12.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rhdf5_2.18.0

loaded via a namespace (and not attached):
[1] zlibbioc_1.20.0 compiler_3.3.2  tools_3.3.
modified 14 months ago by Mike Smith2.9k • written 17 months ago by Kipper Fletez-Brant150
1
14 months ago by
Mike Smith2.9k
EMBL Heidelberg / de.NBI
Mike Smith2.9k wrote:

Sorry for the delay in replying to this, it's taken me a while to get myself acquainted with the rhdf5 source code.

I think the issue here, is that you're not using h5readAttributes() in quite the way it was designed.  The second argument (e.g name = "nchroms") isn't intended to take the name of a specific attribute.  Rather it takes the name of the object (group, dataset, etc) within the file whose attributes you want to get.  In this case that would be the root group "/". The attribute is added to that group because you passed a file handle to the h5obj argument in h5writeAttribute().

> h5readAttributes(tmp, "/")
\$nchroms
[,1]
[1,]    1

This does feel inconsistent between h5writeAttribute() and h5readAttributes(), so I'll see if I can design something more intuitive, or at least clarify things a bit in the manual page.