Skip to content

Instantly share code, notes, and snippets.

Created May 9, 2017 15:52
What would you like to do?
Load a Python/pandas data frame from an HDF5 file into R
#' @param h5File HDF5 file path
#' @param dataset data frame path in the HDF5 file
#' @examples
#' df <- loadhdf5data("/path/to/file.hdf5", "/path/to/dataset")
loadhdf5data <- function(h5File, dataset) {
require(h5) # available on CRAN
f <- h5file(h5File)
nblocks <- h5attr(f[dataset], "nblocks")
data <-, lapply(seq_len(nblocks)-1, function(i) {
data <-[paste0(dataset, "/block", i, "_values")][])
colnames(data) <- f[paste0(dataset, "/block", i, "_items")][]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment