5

I am unable to work with hdf files in R. I believe the R package hdf5 would be what I need to work with these files, but am having difficulty installing it. I get the following warning:

> install.packages("hdf5")
Installing package(s) into ‘C:/Users/ME/Documents/R/win-library/2.15’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---

   package ‘hdf5’ is available as a source package but not as a binary

    Warning message:
package ‘hdf5’ is not available (for R version 2.15.2) 

Does anyone have experience setting up a Windows OS version of R to read and work with hdf files? An example of an hdf file that I am hoping to work with can be found here.

rinni
  • 2,246
  • 1
  • 18
  • 21
Marc in the box
  • 11,769
  • 4
  • 47
  • 97

2 Answers2

15

The Bioconductor rhdf5 package is available on all platforms and does not have system dependencies.

source("http://bioconductor.org/biocLite.R")
biocLite("rhdf5")

and then each session

library("rhdf5")
Martin Morgan
  • 45,935
  • 7
  • 84
  • 112
  • If "work with HDF files" meant to be creating your own instead of reading contents of the existing its OK. But I am looking for the way to read it and biocLite(rhdf5) only provides interface for creating it and play with what you created, according to official documentation. – EpiGen Jan 25 '16 at 19:07
  • @EpiGen can you clarify what you mean? Of course you can use the package to read an existing hdf5 file, whether created by the package itself (section 3.2 of the [vignette](http://bioconductor.org/packages/release/bioc/manuals/rhdf5/man/rhdf5.pdf), for instance) or created outside R. – Martin Morgan Jan 25 '16 at 21:23
  • You are right. I missed that part reading late in the night. So I checked and tested it does read h5 files created outside R. Vote up for "open ur eyes". I know this is another question but what about HDF4 files? Could you suggest anything to read it in R? – EpiGen Jan 26 '16 at 15:33
7

You need to compile the package first. See Rtools for help.

On the CRAN page of HDF5 you can see from the ReadMe that dependencies are missing on the Windows build machines used by CRAN. Maybe you can compile these dependencies on your own.

Actually here there is a guide in the package (win_readme.txt):

hdf5 R package - Windows Read Me:

To compile and then use the hdf5 library, you need the Windows binary of the hdf5 library available at: http://hdf.ncsa.uiuc.edu. We tested it with the Windows binary version 1.4.3.

Download the zip package and unzip it somewhere (for instance, in c:\temp; this dir will be called hereunder).

1) Compilation of the library:

  • Unzip the current source files of the library in \src\hdf5, if it is not already done.

  • Copy hdf5dll.dll from \5-143-win\c\release\dll to \src\hdf5\src

  • Copy \5-143-win\c\release\include to \src\hdf5\src\include (all files in this dir)

  • Now you should compile successfully as usually with Rcmd INSTALL %R_HOME%\src\hdf5

  • You can zip the dir \library\hdf5 for making installable Windows binary package

2) Installation of the hdf5 library:

You cannot run function in this package if you do not put the corresponding hdf5dll.dll in your path... WARNING: using a different version of the dll than the one that was used for compilation could crash R!

rinni
  • 2,246
  • 1
  • 18
  • 21
  • This is an excellent tutorial. Sadly, you get completely KISS'd (the famous "keep it simple, stupid") by Martin's suggestion to use a different package. – Carl Witthoft Feb 04 '13 at 16:21
  • @Carl Witthoft: Well, that's life. But I'm happy to learn about `rhdf5` :) – rinni Feb 04 '13 at 16:41
  • +1 Jeez - I don't know how to choose here. Both great suggestions. I'm pretty stupid though, so I opted for rhdf5. Thanks @rinni – Marc in the box Feb 05 '13 at 19:24