R/read_matrix.R

Defines functions read_matrix

read_matrix <- function(path,
                        transpose=FALSE,
                        as_sparse=TRUE,
                        verbose,
                        ...){
  if(is.character(path)){
    messager("+ Expression matrix (.mtx/.csv/.tsv) detected.",
             "Importing as sparse matrix.",v=verbose)
    obj <- data.table::fread(path,
                             ...)
  } else {
    obj <- path
  }
  #### Convert to sparse matrix ####
  if(isTRUE(as_sparse)){
    obj <- to_sparse(obj = obj,
                     verbose = verbose)
  }
  if(isTRUE(transpose)){
    messager("Transposing matrix.",v=verbose)
    obj <- Matrix::t(obj)
  }
  #### Report dimensions ####
  messager("Matrix dimensions:",paste(dim(obj),sep=" x "), v=verbose)
  #### Return ####
  return(obj)
}
bschilder/scKirby documentation built on Oct. 2, 2024, 10:16 p.m.