From 39dc0a3a29e9777e992b4f668c5f43fd1d105849 Mon Sep 17 00:00:00 2001 From: Ilia Kats Date: Wed, 11 Oct 2023 16:43:40 +0200 Subject: [PATCH] fix writing matrices with NAs --- R/write_h5mu.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/write_h5mu.R b/R/write_h5mu.R index 851f2e5..5bc47bc 100644 --- a/R/write_h5mu.R +++ b/R/write_h5mu.R @@ -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")) @@ -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