Skip to content

Commit

Permalink
Change internal var names to avoid conflicts
Browse files Browse the repository at this point in the history
See Issue #51.
  • Loading branch information
mikemc committed Sep 12, 2020
1 parent 0f3ba32 commit 57dd0b2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
22 changes: 11 additions & 11 deletions R/merge_taxa_vec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand Down

0 comments on commit 57dd0b2

Please sign in to comment.