Search code examples
rhdf5rhdf5

Unable to read hdf5 files in R from Matlab v7


I'm trying to read in .mat files from matlab v7.

I tried the following code, expecting lapply to assign mydata a list containing the data from each file.

> library(rhdf5)
> base :: setwd('filepath')
> filenames <- base::list.files(
>    path = ('filepath'), 
>    recursive = TRUE,
>    pattern = "*.mat"
> )
> mydata <- lapply(filenames, function(x) h5read(x))

Instead I received the following code:

> Error in H5Fopen(file, flags = flags, fapl = fapl, native = native) : 
> HDF5. File accessibilty. Unable to open file.

I've also looked at the Bioconducter website, but I can only find solutions for downloaded data, not locally stored data.


Solution

  • I was able to solve this issue by using a different package called raveio. Posting as an answer in case anyone else is having a similar issue!

    library(raveio)
    base :: setwd("filepath")
    filenames <- base::list.files(
      path = ("fiepath"), # Insert your relevant filepath here
      recursive = TRUE,
      pattern = "*.mat"
    )