tax_mutate: Modify or compute new taxonomic ranks in phyloseq

View source: R/tax_mutate.R

tax_mutateR Documentation

Modify or compute new taxonomic ranks in phyloseq

Description

Add or overwrite tax_table ranks. Use dplyr::mutate() syntax.

Usage

tax_mutate(ps, ...)

Arguments

ps

phyloseq object with a tax_table, or just a tax_table

...

passed straight to dplyr::mutate (see examples and dplyr::mutate help)

Value

phyloseq object with modified tax_table

See Also

mutate

ps_mutate

Examples

library(phyloseq)
library(dplyr)
data("dietswap", package = "microbiome")

# compute new rank
tax_mutate(dietswap, loud_genus = toupper(Genus)) %>%
  tt_get() %>%
  head()

# overwrite a current rank
tax_mutate(dietswap, Genus = toupper(Genus)) %>%
  tt_get() %>%
  head()

# overwrite all ranks
tax_mutate(dietswap, across(everything(), .fns = toupper)) %>%
  tt_get() %>%
  head()

# add a new rank at the beginning
tax_mutate(dietswap, Root = "Bacteria", .before = 1) %>%
  tt_get() %>%
  head()

# this is an error as ranks can't be any other class than character
# tax_mutate(dietswap, Genus = 1:ntaxa(dietswap))

david-barnett/microViz documentation built on April 17, 2025, 4:25 a.m.