grimbough / rhdf5

Package providing an interface between HDF5 and R
http://bioconductor.org/packages/rhdf5
61 stars 22 forks source link

Unnecessary error when dealing with empty character vectors #26

Closed LTLA closed 5 years ago

LTLA commented 5 years ago

The following code emits an unnecessary message (it says "Error", but it still actually returns):

library(rhdf5)
h5createFile("whee.h5")
h5write(character(0), "whee.h5", "stuff")
h5read("whee.h5", "stuff")
## Error in H5Dread(h5dataset = h5dataset, h5spaceFile = h5spaceFile, h5spaceMem = h5spaceMem,  : 
##  Not enough memory to read data! Try to read a subset of data by specifying the index or count parameter.

In addition, the return value is NULL rather than the correct character(0).

The message disappears when h5write is given a non-empty vector.

Session information ``` R Under development (unstable) (2018-11-02 r75535) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 16.04.5 LTS Matrix products: default BLAS: /home/cri.camres.org/lun01/Software/R/trunk/lib/libRblas.so LAPACK: /home/cri.camres.org/lun01/Software/R/trunk/lib/libRlapack.so locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8 [5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] rhdf5_2.27.0 loaded via a namespace (and not attached): [1] compiler_3.6.0 Rhdf5lib_1.5.0 ```
grimbough commented 5 years ago

Thanks for the report. This should be fixed in version 2.27.2

> h5File <- tempfile(pattern = "ex_read", fileext = ".h5")
> h5createFile(h5File)
> h5write(obj = character(0), file = h5File, name = "char")
> h5read(file = h5File, name = "char")
character(0)

Also fixed for integer(0) and double(0) but not other types yet.

LTLA commented 5 years ago

Thanks @grimbough, works like a charm.