david-barnett / microViz

R package for microbiome data visualization and statistics. Uses phyloseq, vegan and the tidyverse. Docker image available.
https://david-barnett.github.io/microViz/
GNU General Public License v3.0
94 stars 10 forks source link

error in taxatree_stats_p_adjust when using grouping = c("rank","term") #119

Closed SilasK closed 11 months ago

SilasK commented 11 months ago

I tried to use grouping = c("rank","term") in taxatree_stats_p_adjust .

It gives me the folowing error:

Error in `dplyr::mutate()`:
ℹ In argument: `dplyr::across(...)`.
Caused by error:
! All unnamed arguments must be length 1
Backtrace:
  1. bb_models %>% taxatree_models2stats(param = "mu") %>% ...
  2. microViz::taxatree_stats_p_adjust(...)
  4. dplyr:::mutate.data.frame(...)
  5. dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
  7. dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
  8. dplyr:::expand_across(dot)
  9. dplyr:::across_setup(...)
 11. glue::glue(names, .envir = glue_mask)
 12. glue::glue_data(...)
 13. base::stop("All unnamed arguments must be length 1", call. = FALSE)

working example, adapted from documentation


# This example is an abbreviated excerpt from article on taxon modelling on
# the microViz documentation website

library(corncob)
library(dplyr)
data("ibd_phylo", package = "corncob")

# We'll keep only the Ulcerative Colitis and Healthy Control samples, to
# simplify the analyses for this example. We'll also remove the Species
# rank information, as most OTUs in this dataset are not assigned to a
# species. We'll also use `tax_fix` to fill any gaps where the Genus is
# unknown, with the family name or whatever higher rank classification is
# known.

phylo <- ibd_phylo %>%
  ps_filter(DiseaseState %in% c("UC", "nonIBD")) %>%
  tax_mutate(Species = NULL) %>%
  tax_fix()

# Let's make some sample data variables that are easier to use and compare
# in the statistical modelling ahead. We will convert dichotomous
# categorical variables into similar binary variables (values: 1 for true,
# or 0 for false). We will also scale and center the numeric variable for
# age.

phylo <- phylo %>%
  ps_mutate(
    UC = ifelse(DiseaseState == "UC", yes = 1, no = 0),
    female = ifelse(gender == "female", yes = 1, no = 0),
    antibiotics = ifelse(abx == "abx", yes = 1, no = 0),
    steroids = ifelse(steroids == "steroids", yes = 1, no = 0),
    age_scaled = scale(age, center = TRUE, scale = TRUE)
  )

bb_models <- phylo %>%
  tax_fix() %>%
  tax_prepend_ranks() %>%
  tax_filter(min_prevalence = 0.3) %>%
  taxatree_models(
    type = corncob::bbdml,
    ranks = c("Phylum", "Class", "Order"),
    variables = c("UC", "female", "antibiotics", "steroids", "age_scaled")
  )

bb_stats <- bb_models %>%
  taxatree_models2stats(param = "mu") %>%
  taxatree_stats_p_adjust(method = "BH", grouping = c("rank","term")) # I modified this line only

bb_stats

bb_stats %>% taxatree_stats_get()
david-barnett commented 11 months ago

Hi Silas

Thanks for reporting with reprex, bug fix incoming for new version

The problem I believe is the new_var argument's default becomes length two when grouping is length two, which isn't compatible with my internal use of something like dplyr(across(..., .names = new_var))

If you specify the new_var arg explicitly, it should work with the current microViz version

bb_stats <- bb_models %>%
  taxatree_models2stats(param = "mu") %>%
  taxatree_stats_p_adjust(method = "BH", grouping = c("rank","term"), new_var = "whatevernameyouwant")