Skip to content

Commit

Permalink
reading: cast 1D-arrays to vectors and 2D-vectors to matrices
Browse files Browse the repository at this point in the history
this is needed to satisfy testthat
  • Loading branch information
ilia-kats committed Oct 12, 2023
1 parent 3365972 commit 4f4f4ae
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion R/read_h5mu.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ read_matrix <- function(dataset, backed=FALSE) {
cls <- "Dense_H5ADMatrixSeed"
seed <- HDF5Array::HDF5ArraySeed
} else {
return(H5Dread(dataset))
dset <- H5Dread(dataset)
if (length(dim(dset)) == 1)
dset <- as.vector(dset)
else if (length(dim(dset)) == 2)
dset <- as.matrix(dset)
return(dset)
}
}
if (backed) {
Expand Down Expand Up @@ -214,6 +219,10 @@ read_array <- function(attr, encoding, strict=TRUE) {
check_encodingversion(attr, encoding, "0.2.0")

ret <- H5Dread(attr)
if (length(dim(ret)) == 1)
ret <- as.vector(ret)
else if (length(dim(ret)) == 2)
ret <- as.matrix(ret)
# h5py saves boolean arrays as HDF5 enums
if (is.factor(ret) && all(levels(ret) == c("FALSE", "TRUE"))) {
ret <- as.logical(ret)
Expand Down

0 comments on commit 4f4f4ae

Please sign in to comment.