本文介绍了保存在hdf5save中会创建一个不可读的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R将数组另存为HDF5文件,但是没有运气.

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

要尝试诊断问题,我运行了example(hdf5save).这样成功创建了一个HDF5文件,我可以使用h5dump轻松阅读该文件.

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

当我然后手动运行R代码时,我发现它不起作用.我运行的代码与示例脚本中运行的代码完全相同(除了更改文件名以避免覆盖外).这是代码:

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)

这是h5dump的错误消息:

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

有人有什么想法吗?我完全不知所措.

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

谢谢

推荐答案

我遇到了这个问题.我不确定原因,也不是hdf5维护者. R软件包的作者尚未答复.

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.

可行的替代方案

自我最初回答以来, hdf5 软件包已存档,并且合适的替代方法(h5rrhdf5和ncdf4 ) have been created; I am currently using ncdf4`:

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. 由于netCDF-4使用hdf5作为存储层,因此 ncdf4 包提供了到netCDF-4和hdf5的接口.
  2. h5r 包,R> = 2.10
  3. rhdf5 包在BioConductor上可用.
  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. 安装R 2.7,hdf5版本1.6.6,R hdf5 v1.6.7 和zlib1g版本1:1.2.3.3,并在编写文件时使用它(这是我的解决方案,直到迁移到ncdf4库为止).
  2. 在[hdf5utils] [1]程序的命令行中使用h5totxt(需要使用bash并重写R代码)
  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)

该问题的最小重现性演示:

这是一个可重现的示例,它发送错误

Here is a reproducible example that sends an error

第一次R会话

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

第二次R会话:

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

输出:

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

这篇关于保存在hdf5save中会创建一个不可读的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 09:49