A package that allows to interface with the HDF5 C-library. Provides access to most of its functionality from inside R using R6 classes. For more details please see the README at the github page https://github.com/hhoeflin/hdf5r.

Examples

test_file <- tempfile(fileext=".h5")
file.h5 <- H5File$new(test_file, mode="w")

data(cars)
file.h5$create_group("test")
#> Class: H5Group
#> Filename: /tmp/Rtmp0t2L4j/file3bd62261ab32.h5
#> Group: /test
file.h5[["test/cars"]] <- cars
cars_ds <- file.h5[["test/cars"]]
h5attr(cars_ds, "rownames") <- rownames(cars)

# Close the file at the end
# the 'close' method closes only the file-id, but leaves object inside the file open
# This may prevent re-opening of the file. 'close_all' closes the file and all objects in it
file.h5$close_all()
# now re-open it 
file.h5 <- H5File$new(test_file, mode="r+")

# lets look at the content
file.h5$ls(recursive=TRUE)
#>        name     link.type    obj_type num_attrs group.nlinks group.mounted
#> 1      test H5L_TYPE_HARD   H5I_GROUP         0            1             0
#> 2 test/cars H5L_TYPE_HARD H5I_DATASET         1           NA            NA
#>   dataset.rank dataset.dims dataset.maxdims dataset.type_class
#> 1           NA         <NA>            <NA>               <NA>
#> 2            1           50             Inf       H5T_COMPOUND
#>   dataset.space_class committed_type
#> 1                <NA>           <NA>
#> 2          H5S_SIMPLE           <NA>

cars_ds <- file.h5[["test/cars"]]
# note that for now tables in HDF5 are 1-dimensional, not 2-dimensional
mycars <- cars_ds[]
h5attr_names(cars_ds)
#> [1] "rownames"
h5attr(cars_ds, "rownames")
#>  [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12" "13" "14" "15"
#> [16] "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
#> [31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43" "44" "45"
#> [46] "46" "47" "48" "49" "50"

file.h5$close_all()