Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing new preserve argument in tax_agg #75

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: microViz
Title: Microbiome Data Analysis and Visualization
Version: 0.10.0
Version: 0.10.0.9000
Authors@R:
person(given = "David",
family = "Barnett",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# microViz (development version)

# microViz 0.10.0

Major internal changes from S3 ps_extra to S4 psExtra objects. See [article about this change](../articles/ps_extra-replaced.html)
Expand Down
13 changes: 13 additions & 0 deletions R/tax_agg.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ tax_agg <- function(ps,
sort_by = NA,
top_N = NA,
force = FALSE,
preserve = NULL,
add_unique = FALSE) {
stopif_ps_extra(ps, argName = "ps")
check_is_phyloseq(ps, argName = "ps")
Expand Down Expand Up @@ -150,6 +151,18 @@ tax_agg <- function(ps,
stop("zero-length name(s) in tax_table at rank: ", rank, taxFixPrompt())
}

# copy taxa names to aggregation rank if some taxa marked as preserved
if (!is.null(preserve)) {
preserve <- rlang::arg_match(
arg = preserve, values = uniqueNamesAtRank, multiple = TRUE
)
preserved <- tt_df[[rank_index]] %in% preserve
tt_df[preserved, rank_index] <- rownames(tt_df)[preserved]
uniqueNamesAtRank <- unique(tt_df[, rank_index])
# change name of rank to indicate it's not a pure rank aggregation
rank <- names(tt_df)[names(tt_df) == rank] <- paste(rank, "& unique")
}

if (isTRUE(force)) {
# FORCED aggregation: doesn't care/check if higher ranks are not unique
tt_distinct <- dplyr::distinct(
Expand Down
1 change: 1 addition & 0 deletions man/tax_agg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.