From dabaaba208f4af5df56d45d836a42e9a47d60c7c Mon Sep 17 00:00:00 2001 From: "Martin R. Smith" <1695515+ms609@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:57:18 +0100 Subject: [PATCH] Progress bar for `.MaxInfo()` --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 4 +++- R/tree_distance.R | 18 +++++++++++------- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ac860edce..5710565b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: TreeDist Type: Package Title: Calculate and Map Distances Between Phylogenetic Trees -Version: 2.7.1.9003 +Version: 2.7.1.9004 Authors@R: c(person("Martin R.", "Smith", email = "martin.smith@durham.ac.uk", role = c("aut", "cre", "cph", "prg"), diff --git a/NAMESPACE b/NAMESPACE index 31ea6fbef..ff9c6bbca 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -164,6 +164,7 @@ importFrom(ape,plot.phylo) importFrom(cli,cli_alert_danger) importFrom(cli,cli_alert_info) importFrom(cli,cli_alert_success) +importFrom(cli,cli_progress_along) importFrom(cli,cli_progress_bar) importFrom(cli,cli_progress_update) importFrom(colorspace,qualitative_hcl) diff --git a/NEWS.md b/NEWS.md index 7eaf32b95..0abf75525 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,11 @@ -# TreeDist 2.7.1.9003 (2024-06-28) +# TreeDist 2.7.1.9004 (2024-07-25) - `Islands()` allows the identification of islands of trees. - Internal implementation of path and SPR distances, removing dependency on phangorn (and thus R 4.4). + +- Add progress bar within `.MaxValue()` # TreeDist 2.7.1 (2024-06-13) diff --git a/R/tree_distance.R b/R/tree_distance.R index 4bdcd7e48..86c88614a 100644 --- a/R/tree_distance.R +++ b/R/tree_distance.R @@ -73,6 +73,8 @@ GeneralizedRF <- function(splits1, splits2, nTip, PairScorer, ret } + +#' @importFrom cli cli_progress_along .MaxValue <- function(tree1, tree2, Value) { lab1 <- TipLabels(tree1) sameTips <- .AllTipsSame(lab1, TipLabels(tree2)) @@ -95,13 +97,15 @@ GeneralizedRF <- function(splits1, splits2, nTip, PairScorer, pairs <- combn(seq_along(tree1), 2) nPairs <- dim(pairs)[[2]] - apply(pairs, 2, function(ij) { - i <- ij[[1]] - j <- ij[[2]] - common <- intersect(lab1[[i]], lab1[[j]]) - Value(KeepTip(tree1[[i]], common)) + - Value(KeepTip(tree1[[j]], common)) - }) + vapply(cli_progress_along(seq_len(nPairs), "Calc max value"), + function(pair) { + i <- pairs[1, pair] + j <- pairs[2, pair] + common <- intersect(lab1[[i]], lab1[[j]]) + Value(KeepTip(tree1[[i]], common)) + + Value(KeepTip(tree1[[j]], common)) + }, double(1)) + } } else { value1 <- Value(tree1)