Search
Question: Contradictory Messages from rhdf5
0
gravatar for Kipper Fletez-Brant
6 months ago by
United States
Kipper Fletez-Brant140 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")

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?

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.
ADD COMMENTlink modified 3 months ago by Mike Smith2.1k • written 6 months ago by Kipper Fletez-Brant140
1
gravatar for Mike Smith
3 months ago by
Mike Smith2.1k
EMBL Heidelberg / de.NBI
Mike Smith2.1k 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.

ADD COMMENTlink modified 3 months ago by Wolfgang Huber13k • written 3 months ago by Mike Smith2.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 149 users visited in the last hour