R/otu_matrix.R

Defines functions otu.matrix

Documented in otu.matrix

#' @name otu.matrix
#' @title otu_table to matrix
#' @description Extract otu_table from a phyloseq object and turn it into a matrix
#' @param ps a phyloseq object
#' @seealso \code{\link{as}}, \code{\link{phyloseq}}, \code{\link{otu_table}}
#' @export
#' @examples
#' data(example_phyloseq)
#' otu.mat <- otu.matrix(example_phyloseq)
#' View(otu.mat)

otu.matrix <- function(ps, force.taxa.cols = TRUE) {
  mat <- as(phyloseq::otu_table(ps), "matrix")
  if (taxa_are_rows(ps) & force.taxa.cols) {
    mat <- t(mat)
  }
  return(mat)
}
kstagaman/phyloseqCompanion documentation built on Aug. 26, 2022, 5:07 a.m.