These functions extend the as_tibble()
function defined by the tibble
package to work on phyloseq objects or phyloseq-component objects.
# S3 method for otu_table as_tibble(x, pivot = TRUE, .name_repair = base::make.unique) # S3 method for sample_data as_tibble(x, .name_repair = base::make.unique) # S3 method for taxonomyTable as_tibble(x, .name_repair = base::make.unique) # S3 method for XStringSet as_tibble(x) # S3 method for phyloseq as_tibble(x, tax = TRUE, ref = FALSE, .name_repair = base::make.unique)
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. |
A tibble (tbl_df)
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.
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)#> Error in filter_tax_table(., dplyr::row_number()%%100 == 1): could not find function "filter_tax_table"#> Error in psmelt(ps): object 'ps' not foundas_tibble(ps) %>% glimpse#> Error in as_tibble(ps): object 'ps' not found# By default, the otu_table method provides a tibble in long-format like # psmelt and the phyloseq method otu_table(ps) %>% as_tibble %>% glimpse#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'otu_table': object 'ps' not found# 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#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'sample_data': error in evaluating the argument 'object' in selecting a method for function 'sample_data': object 'ps' not found#> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'sample_data': object 'ps' not found