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)
}
muschellij2/cifti documentation built on May 25, 2018, 6:29 p.m.