R/cifti_brain_structs.R

Defines functions cifti_brain_structs

Documented in cifti_brain_structs

#' @title Extract Brain Structures from CIFTI Brain Models
#' @description Extracts the \code{BrainStructure} attribute from a
#' \code{BrainModel} in a \code{cifti} object
#'
#' @param file \code{cifti} object
#'
#' @return A vector of brain structure names
#' @export
cifti_brain_structs = function(file) {
  if (is.cifti(file)) {
    cii = file
  } else {
    cii = read_cifti(file)
  }
  struct_names = sapply(cii$BrainModel, function(x) {
    if (is.list(x)) {
      return(sapply(x, attr, "BrainStructure"))
    }
    attr(x, "BrainStructure")
  })
  struct_names = unlist(struct_names)
  return(struct_names)
}
muschellij2/cifti documentation built on Aug. 12, 2020, 4:06 a.m.