R/sample_data_table.R

Defines functions sample.data.table

Documented in sample.data.table

#' @name sample.data.table
#' @title sample_data to data.table
#' @description Extract sample_data from a phyloseq object and turn it into a data.table
#' @param ps a phyloseq object
#' @param sample.column.name the name of the column to keep sample names (because data.table doesn't use row names). Defaults to "Sample". Can set to FALSE to drop sample names.
#' @seealso \code{\link{data.table}}, \code{\link{phyloseq}}, \code{\link{sample_data}}
#' @export
#' @examples
#' data(example_phyloseq)
#' smpl.DT <- sample.data.table(example_phyloseq)
#' smpl.DT

sample.data.table <- function(ps, sample.column.name = "Sample") {
  return(
    data.table::as.data.table(
      as(phyloseq::sample_data(ps), "data.frame"),
      keep.rownames = sample.column.name
    )
  )
}
kstagaman/phyloseqCompanion documentation built on Aug. 26, 2022, 5:07 a.m.