From 56e587d9c361da309ceea27bddb23b0a49f40ffc Mon Sep 17 00:00:00 2001 From: "Martin R. Smith" <1695515+ms609@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:16:47 +0100 Subject: [PATCH 1/4] Update R-CMD-check.yml --- .github/workflows/R-CMD-check.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/R-CMD-check.yml b/.github/workflows/R-CMD-check.yml index 806cb3925..674e726e2 100644 --- a/.github/workflows/R-CMD-check.yml +++ b/.github/workflows/R-CMD-check.yml @@ -48,9 +48,9 @@ jobs: config: - {os: windows-latest, r: 'release'} - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: '4.1', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-latest, r: '4.1', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-latest, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-latest, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} env: _R_CHECK_CRAN_INCOMING_: true # Seemingly not set by --as-cran @@ -71,21 +71,21 @@ jobs: uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} + extra-repositories: https://ms609.github.io/packages/ - name: Install apt packages (Linux) if: runner.os == 'Linux' run: | sudo apt-get update - sudo apt-get install -y \ - texlive-latex-base texlive-fonts-recommended libcurl4-openssl-dev \ - libglpk40 - + sudo apt-get install -y texlive-latex-base texlive-fonts-recommended + - name: Set up R dependencies (Windows) if: runner.os == 'Windows' uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: | RcppCore/Rcpp + ms609/TreeTools ms609/TreeDistData needs: | check @@ -96,9 +96,10 @@ jobs: uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: | - ms609/TreeDistData RcppCore/Rcpp - phangorn=?ignore-before-r=4.1.0 + ms609/TreeTools + ms609/TreeDistData + phangorn=?ignore-before-r=4.4.0 ggplot2=?ignore-before-r=4.4.0 hypervolume=?ignore-before-r=4.4.0 kdensity=?ignore-before-r=4.4.0 From be46537eeb6796b7fb827c8acbe58b1d4f83b5f5 Mon Sep 17 00:00:00 2001 From: "Martin R. Smith" <1695515+ms609@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:56:12 +0100 Subject: [PATCH 2/4] test l2cons --- tests/testthat/test-information.R | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-information.R b/tests/testthat/test-information.R index b0d3513f0..f4421b363 100644 --- a/tests/testthat/test-information.R +++ b/tests/testthat/test-information.R @@ -44,15 +44,20 @@ test_that("TreesConsistentWithTwoSplits works", { Test <- function(n, a, b, score) { logScore <- log(score) + l2Score <- log2(score) - expect_equal(score, TreesConsistentWithTwoSplits(n, a, b)) - expect_equal(score, TreesConsistentWithTwoSplits(n, b, a)) - expect_equal(score, TreesConsistentWithTwoSplits(n, n - a, n - b)) - expect_equal(score, TreesConsistentWithTwoSplits(n, n - b, n - a)) - expect_equal(logScore, LnTreesConsistentWithTwoSplits(n, a, b)) - expect_equal(logScore, LnTreesConsistentWithTwoSplits(n, b, a)) - expect_equal(logScore, LnTreesConsistentWithTwoSplits(n, n - a, n - b)) - expect_equal(logScore, LnTreesConsistentWithTwoSplits(n, n - b, n - a)) + expect_equal(TreesConsistentWithTwoSplits(n, a, b), score) + expect_equal(TreesConsistentWithTwoSplits(n, b, a), score) + expect_equal(TreesConsistentWithTwoSplits(n, n - a, n - b), score) + expect_equal(TreesConsistentWithTwoSplits(n, n - b, n - a), score) + expect_equal(Log2TreesConsistentWithTwoSplits(n, a, b), l2Score) + expect_equal(Log2TreesConsistentWithTwoSplits(n, b, a), l2Score) + expect_equal(Log2TreesConsistentWithTwoSplits(n, n - a, n - b), l2Score) + expect_equal(Log2TreesConsistentWithTwoSplits(n, n - b, n - a), l2Score) + expect_equal(LnTreesConsistentWithTwoSplits(n, a, b), logScore) + expect_equal(LnTreesConsistentWithTwoSplits(n, b, a), logScore) + expect_equal(LnTreesConsistentWithTwoSplits(n, n - a, n - b), logScore) + expect_equal(LnTreesConsistentWithTwoSplits(n, n - b, n - a), logScore) } Test(8, 3, 0, 315) From c5fa1792c76b6121bdf2187e74e96744f64caba4 Mon Sep 17 00:00:00 2001 From: "Martin R. Smith" <1695515+ms609@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:59:07 +0100 Subject: [PATCH 3/4] .MeanMSTEdge.dist --- R/cluster_stats.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/cluster_stats.R b/R/cluster_stats.R index 7f9547948..8690e3a54 100644 --- a/R/cluster_stats.R +++ b/R/cluster_stats.R @@ -226,7 +226,7 @@ MeanMSTEdge.dist <- function(x, cluster = 1) { d <- as.matrix(x) diag(d) <- NA_real_ vapply(seq_along(unique(cluster)), - function(i) .MeanNN.dist(d[cluster == i, cluster == i, drop = FALSE]), + function(i) .MeanMSTEdge.dist(d[cluster == i, cluster == i, drop = FALSE]), numeric(1)) } From ed1423acde70a8161b3884cec539fee8385ea059 Mon Sep 17 00:00:00 2001 From: "Martin R. Smith" <1695515+ms609@users.noreply.github.com> Date: Thu, 27 Jun 2024 13:03:51 +0100 Subject: [PATCH 4/4] Test coverage --- R/tree_distance_kendall-colijn.R | 2 +- tests/testthat/test-tree_distance_kc.R | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/R/tree_distance_kendall-colijn.R b/R/tree_distance_kendall-colijn.R index 76abc7ca6..4eefdaf3f 100644 --- a/R/tree_distance_kendall-colijn.R +++ b/R/tree_distance_kendall-colijn.R @@ -239,7 +239,7 @@ KCDiameter.numeric <- function(tree) { #' @export KCDiameter.list <- function(tree) { - lapply(tree, KCDiameter) + vapply(tree, KCDiameter, double(1)) } #' @export diff --git a/tests/testthat/test-tree_distance_kc.R b/tests/testthat/test-tree_distance_kc.R index 30063673f..136d9e43b 100644 --- a/tests/testthat/test-tree_distance_kc.R +++ b/tests/testthat/test-tree_distance_kc.R @@ -1,5 +1,10 @@ library("TreeTools", quietly = TRUE) +test_that("KC fails gracefully", { + expect_error(KendallColijn(BalancedTree(8), BalancedTree(1:8)), + "Leaves must bear identical labels.") +}) + test_that("KC vector calculations", { bal7 <- ape::read.tree(text = "(((t1,t2),(t3,t4)),((t5,t6),t7));") @@ -45,9 +50,11 @@ test_that("KCDiameter() calculated", { Test(4) Test(40) tree1 <- ape::read.tree(text = "(a, (b, (c, (d, (e, (f, (g, h)))))));") + expect_equal(KendallColijn(tree1), 0) tree2 <- ape::read.tree(text = "(a, ((b, c), (d, (e, (f, (g, h))))));") tree3 <- ape::read.tree(text = "(a, (b, (c, (d, (e, (f, g))))));") trees <- c(tree1, tree2, tree3) expect_equal(KCDiameter(trees), c(KCDiameter(tree1), KCDiameter(tree2), KCDiameter(tree3))) + expect_equal(KCDiameter(list(tree1, tree2, tree3)), KCDiameter(trees)) })