Skip to content

Instantly share code, notes, and snippets.

@kieranrcampbell
Created June 13, 2018 20:00
Show Gist options
  • Save kieranrcampbell/d25ac5c8758562b50f10eb5af9bba213 to your computer and use it in GitHub Desktop.
Save kieranrcampbell/d25ac5c8758562b50f10eb5af9bba213 to your computer and use it in GitHub Desktop.
#' Source an HDF5 file (ignoring all groups) where each
#' entry in the HDF5 is read and assigned to a variable
#' in the current environment
#' @importFrom rhdf5 h5ls
source_hdf5 <- function(filename, e) {
ls <- h5ls(filename)
vars <- ls$name
for(var in vars) {
assign(var, h5read(filename, var), envir = e)
}
}
# example usage
source_hdf5("myfile.h5", environment())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment