Skip to content

Commit

Permalink
fix writing matrices with NAs
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-kats committed Oct 11, 2023
1 parent 0d841b1 commit 39dc0a3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion R/write_h5mu.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ write_matrix <- function(parent, key, mat) {
writeAttribute(dset, "encoding-version", "0.2.0")
} else {
grp <- H5Gcreate(parent, key)
naidx <- is.na(mat)
if (is.character(mat))
mat[naidx] <- ""
else
mat[naidx] <- as(0, type(mat))

write_matrix(grp, "values", mat)
write_matrix(grp, "mask", is.na(mat))
writeAttribute(grp, "encoding-type", ifelse(is.logical(mat), "nullable-boolean", "nullable-integer"))
Expand Down Expand Up @@ -413,7 +419,7 @@ write_elem <- function(parent, key, data) {
for (slotnm in slotNames(data)) {
write_elem(grp, slotnm, slot(data, slotnm))
}
writeattribute(grp, "encoding-type", "dict")
writeAttribute(grp, "encoding-type", "dict")
writeAttribute(grp, "encoding-version", "0.1.0")
H5Gclose(grp)
} else
Expand Down

0 comments on commit 39dc0a3

Please sign in to comment.