I think this is related to how Windows treats binary and text files when you download them. I don't know how you obtained the file, but it is the source of the error in my example code. I'll try and demonstrate it here.
First we'll load the library and set the download URL
library(rhdf5)
file_url <- "http://support.hdfgroup.org/ftp/HDF5/examples/files/exbyapi/h5ex_d_sofloat.h5"
Now we'll download the file twice. The first time treating it as a text file, the second as binary. This is specified by the mode
argument.
h5_text_dl <- file.path(tempdir(), "h5.text.h5")
download.file(url = file_url,
destfile = h5_text_dl,
mode = "w")
h5_binary_dl <- file.path(tempdir(), "h5.binary.h5")
download.file(url = file_url,
destfile = h5_binary_dl,
mode = "wb")
The output that is printed to screen is identical, so I'll include it only once. Note that the file is of length 8072 bytes.
trying URL 'http://support.hdfgroup.org/ftp/HDF5/examples/files/exbyapi/h5ex_d_sofloat.h5'
Content type ' â³7û' length 8072 bytes
downloaded 8072 bytes
Now we'll do two operations on the downloaded files; We'll ask for the size of the file, and then we'll try to list the contents. First the 'text' version:
> file.size(h5_text_dl)
[1] 8137
> h5ls(h5_text_dl)
Error in H5Fopen(file, "H5F_ACC_RDONLY") :
HDF5. File accessability. Unable to open file.
Now the binary version:
> file.size(h5_binary_dl)
[1] 8072
> h5ls(h5_binary_dl)
group name otype dclass dim
0 / DS1 H5I_DATASET FLOAT 64 x 32
The text version is not the same size as the original download (Windows has done something!), and it is no longer a valid HDF5 file, hence the error message. With the binary download the file stays intact and can be read.
This doesn't happen on Linux or Mac, but on Windows it's important to set the mode
argument correctly. I've no idea if this also applies to other methods of downloading files, but this was the root cause of my problem.
Is the file in your current directory?
Yes. File is in my current directory.
Can you update your post to include the output from the command
sessionInfo()
so we can see what version of R and rhdf5 you are using? It seems to work fine for me e.g.My sessionInfo is:
Thanks for that. I get the same error when running this with the latest versions on Windows. I'll take a look and try to figure out what is going wrong.