Contradictory Messages from rhdf5
Entering edit mode
Last seen 4.2 years ago
United States


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")

h5readAttributes(tmp, "nchroms")
Error in h5readAttributes(tmp, "nchroms") :
  Object nchroms does not exist in this HDF5 file.

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

What is going on here?

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

[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.
rhdf5 hdf5 • 790 views
Entering edit mode
Mike Smith ★ 5.5k
Last seen 4 hours ago
EMBL Heidelberg / de.NBI

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, "/")
[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.


Login before adding your answer.

Traffic: 831 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6