as_tibble-phyloseq: Coerce phyloseq objects to tibble data frames

as_tibble-phyloseqR Documentation

Coerce phyloseq objects to tibble data frames

Description

These functions extend the as_tibble() function defined by the tibble package to work on phyloseq objects or phyloseq-component objects.

Usage

## S3 method for class 'otu_table'
as_tibble(x, pivot = TRUE, .name_repair = base::make.unique)

## S3 method for class 'sample_data'
as_tibble(x, .name_repair = base::make.unique)

## S3 method for class 'taxonomyTable'
as_tibble(x, .name_repair = base::make.unique)

## S3 method for class 'XStringSet'
as_tibble(x)

## S3 method for class 'phyloseq'
as_tibble(x, tax = TRUE, ref = FALSE, .name_repair = base::make.unique)

Arguments

x

A phyloseq object or component.

pivot

Whether to pivot the otu table to long format.

.name_repair

Function to repair names in the case of conflicts.

tax

Whether to include taxonomy data.

ref

Whether to include reference sequences.

Details

Tibbles (tbl_df objects) do not support rownames; the taxa and sample names in the returned tibbles will always be stored in the first or second columns. The names ".otu", ".sample", ".abundance", and ".sequence" are special column names reserved for the otu/taxa names, sample names, abundances, and reference sequences.

Value

A tibble (tbl_df)

Examples

library(tibble) # for as_tibble() and glimpse()

data(GlobalPatterns)

# Subset to 1/100 of the original taxa to speed operations
ps <- GlobalPatterns %>%
  filter_tax_table(dplyr::row_number() %% 100 == 1)

# On phyloseq objects, as_tibble is similar to psmelt()
psmelt(ps) %>% glimpse
as_tibble(ps) %>% glimpse

# By default, the otu_table method provides a tibble in long-format like
# psmelt and the phyloseq method
otu_table(ps) %>% as_tibble %>% glimpse

# Sample data and taxonomy tables produced by as_tibble can be converted
# back into their respective phyloseq objects using speedyseq's tbl_df
# constructors
sample_data(ps) <- sample_data(ps) %>%
  as_tibble %>%
  dplyr::mutate(sample_sum = sample_sums(ps)) %>%
  sample_data
sample_data(ps) %>% glimpse

mikemc/speedyseq documentation built on April 22, 2024, 6:40 p.m.