Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
717 views
in Technique[技术] by (71.8m points)

r - Saving in hdf5save creates an unreadable file

I'm trying to save an array as a HDF5 file using R, but having no luck.

To try and diagnose the problem I ran example(hdf5save). This successfully created a HDF5 file that I could read easily with h5dump.

When I then ran the R code manually, I found that it didn't work. The code I ran was exactly the same as is ran in the example script (except for a change of filename to avoid overwriting). Here is the code:

(m <- cbind(A = 1, diag(4)))
ll <- list(a=1:10, b=letters[1:8]);
l2 <- list(C="c", l=ll); PP <- pi
hdf5save("ex2.hdf", "m","PP","ll","l2")
rm(m,PP,ll,l2)  # and reload them:
hdf5load("ex2.hdf",verbosity=3)
m        # read from "ex1.hdf"; buglet: dimnames dropped
str(ll)
str(l2)

and here is the error message from h5dump:

h5dump error: unable to open file "ex2.hdf"

Does anyone have any ideas? I'm completely at a loss.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have had this problem. I am not sure of the cause and neither are the hdf5 maintainers. The authors of the R package have not replied.

Alternatives that work

In the time since I originally answered, the hdf5 package has been archived, and suitable alternatives (h5r, rhdf5, and ncdf4) have been created; I am currently usingncdf4`:

  1. Since netCDF-4 uses hdf5 as a storage layer, the ncdf4 package provides an interface to both netCDF-4 and hdf5.
  2. The h5r package with R>=2.10
  3. the rhdf5 package is available on BioConductor.

Workarounds Two functional but unsatisfactory workarounds that I used prior to finding the alternatives above:

  1. Install R 2.7, hdf5 version 1.6.6, R hdf5 v1.6.7, and zlib1g version 1:1.2.3.3 and use this when writing the files (this was my solution until migrating to the ncdf4 library).
  2. Use h5totxt at the command line from the [hdf5utils][1] program (requires using bash and rewriting your R code)

A minimal, reproducible demonstration of the issue:

Here is a reproducible example that sends an error

First R session

library(hdf5)
dat <- 1:10
hdf5save("test.h5","dat")
q()
n # do not save workspace

Second R session:

library(hdf5)
hdf5load("test.h5")

output:

HDF5-DIAG: Error detected in HDF5 library version: 1.6.10 thread
47794540500448.  Back trace follows.
 #000: H5F.c line 2072 in H5Fopen(): unable to open file
   major(04): File interface
   minor(17): Unable to open file
 #001: H5F.c line 1852 in H5F_open(): unable to read superblock
   major(04): File interface
   minor(24): Read failed
 #002: H5Fsuper.c line 114 in H5F_read_superblock(): unable to find file
signature
   major(04): File interface
   minor(19): Not an HDF5 file
 #003: H5F.c line 1304 in H5F_locate_signature(): unable to find a valid
file signature
   major(05): Low-level I/O layer
   minor(29): Unable to initialize object
Error in hdf5load("test.h5") : unable to open HDF file: test.h5

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...