Skip to content

Commit

Permalink
Convert strings to UTF-8 based on the HDF5 cset.
Browse files Browse the repository at this point in the history
This is usually handled by rhdf5's high-level functions, but because we're
using the low-level functions, we need to do it ourselves.
  • Loading branch information
LTLA committed Sep 22, 2024
1 parent ceb265e commit 9021de7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/hdf5.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ h5_read_vector <- function(handle, name, check=FALSE, default=NULL, bit64convers

if (is.raw(output)) {
storage.mode(output) <- "integer"
} else if (is.character(output) && H5Tget_cset(H5Dget_type(dhandle)) == 1L) {
Encoding(output) <- "UTF-8"
}

output
}

Expand All @@ -161,7 +164,10 @@ h5_read_attribute <- function(handle, name, check=FALSE, default=NULL, bit64conv

if (is.raw(output)) {
storage.mode(output) <- "integer"
} else if (is.character(output) && H5Tget_cset(H5Aget_type(ahandle)) == 1L) {
Encoding(output) <- "UTF-8"
}

output
}

Expand Down

0 comments on commit 9021de7

Please sign in to comment.