From 57dd0b20fdc18311f60db72a2e120467192d063a Mon Sep 17 00:00:00 2001 From: Michael McLaren Date: Sat, 12 Sep 2020 15:50:47 -0400 Subject: [PATCH] Change internal var names to avoid conflicts See Issue #51. --- DESCRIPTION | 2 +- NEWS.md | 6 +++--- R/merge_taxa_vec.R | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0dca77a..3d9ed66 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: speedyseq Title: Faster implementations of phyloseq functions -Version: 0.3.2.9003 +Version: 0.4.0 Authors@R: person(given = "Michael", family = "McLaren", diff --git a/NEWS.md b/NEWS.md index f9067f7..312959f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ -# speedyseq 0.3.3 +# speedyseq 0.4.0 -* Add `merge_samples2()` and the helper `unique_or_na()` as an alternative to +* New `merge_samples2()` and helper `unique_or_na()` provides an alternative to `phyloseq::merge_samples()` that better handles categorical sample variables. The `funs` argument specifies which summary is used to merge each sample variable within groups. The default is `unique_or_na()`, which collapses the @@ -22,7 +22,7 @@ sample_data(ps0) %>% head * Add `tibble::glimpse()` methods for `sample_data` and `phyloseq` objects -* Fixed bug in `merge_taxa_vec()` when only one tax rank +* Minor bug fixes to `merge_taxa_vec()` # speedyseq 0.3.2 diff --git a/R/merge_taxa_vec.R b/R/merge_taxa_vec.R index 50eb831..8059fbb 100644 --- a/R/merge_taxa_vec.R +++ b/R/merge_taxa_vec.R @@ -148,10 +148,10 @@ setMethod("merge_taxa_vec", "otu_table", setMethod("merge_taxa_vec", "taxonomyTable", function(x, group, reorder = FALSE, tax_adjust = 1L) { stopifnot(ntaxa(x) == length(group)) - # Temporary stopgap to avoid hidden errors if "taxon" or "group" are in - # the tax table - if (any(c("taxon", "group") %in% rank_names(x))) { - stop("Currently requires that 'taxon' and 'group' are not in `rank_names(x)`") + # Temporary stopgap to avoid hidden errors if internal variable names are + # in the tax table + if (any(c(".taxon", ".group") %in% rank_names(x))) { + stop("Currently requires that '.taxon' and '.group' are not in `rank_names(x)`") } # drop taxa with `is.na(group)` if (anyNA(group)) { @@ -172,23 +172,23 @@ setMethod("merge_taxa_vec", "taxonomyTable", # ranks and making new tax table reduced <- x %>% as("matrix") %>% - data.table::as.data.table(keep.rownames = "taxon") %>% - .[, group := group] %>% + data.table::as.data.table(keep.rownames = ".taxon") %>% + .[, .group := group] %>% .[, # Reduce to one row per group; compute new names and bad ranks - by = group, .SDcols = rank_names(x), + by = .group, .SDcols = rank_names(x), c( # New taxa names are the first taxon in each group - .(taxon = taxon[1]), + .(.taxon = .taxon[1]), lapply(.SD, bad_or_unique, bad = bad_string) ) ] if (reorder) - data.table::setorder(reduced, group) + data.table::setorder(reduced, .group) # For last step, convert to data frame with rownames as taxon names; but # must be a matrix before final call to tax_table - reduced <- reduced[, !"group"] %>% - tibble::column_to_rownames("taxon") + reduced <- reduced[, !".group"] %>% + tibble::column_to_rownames(".taxon") # If only one tax rank, just convert bad_string -> NA; else, need to # propagate bad ranks downwards and convert to NAs if (identical(length(rank_names(x)), 1L)) {