R/cifti_read_char.R

Defines functions cifti_read_char

Documented in cifti_read_char

#' @title Read characters with embedded nulls
#' @description Simple wrapper for reading in character values with embedded nulls in a
#' binary file
#' @param fid identifier of the open file connection
#' @param n number of elements to read
#' @param to A character string describing the target encoding.
#'
#' @return Character vector
#' @export
cifti_read_char = function(fid, n, to = "UTF-8") {
  txt <- readBin(con = fid, what = "raw", n = n)
  iconv(rawToChar(txt[txt != as.raw(0)]), to = to)
}
neuroconductor/cifti documentation built on May 19, 2021, 5:18 a.m.