diff --git a/R/bias-helpers.R b/R/bias-helpers.R index 585abfe..4f5c587 100644 --- a/R/bias-helpers.R +++ b/R/bias-helpers.R @@ -21,6 +21,13 @@ NULL #' @describeIn cooccurrence Adjacency matrix of the co-occurrence network #' @export cooccurrence_matrix <- function(mat, all = TRUE) { + # To compute the number of times each pair of taxa cooccur, we leverage the + # `compute_ratios()` function. Doing so requires that the samples (rows of + # `mat`) and the taxa (cols of `mat`) have names. + if (is.null(rownames(mat))) + rownames(mat) <- paste0("S", seq(nrow(mat))) + if (is.null(colnames(mat))) + colnames(mat) <- paste0("T", seq(ncol(mat))) ratios <- mat %>% tibble::as_tibble(rownames = "Sample") %>% tidyr::gather("Taxon", "Value", -Sample) %>% diff --git a/tests/testthat/test-center.R b/tests/testthat/test-center.R index b125d5d..0f40e9d 100644 --- a/tests/testthat/test-center.R +++ b/tests/testthat/test-center.R @@ -117,6 +117,14 @@ test_that("sampling rows or using `weights` gives an equal estimate", { center(d2, weights = w.rows, method = "rss")) }) +test_that("the center is correctly computed when sample and taxa names are missing", { + d2.no_names <- d2 + rownames(d2.no_names) <- colnames(d2.no_names) <- NULL + c1 <- center(d2) + names(c1) <- NULL + c2 <- center(d2.no_names) + expect_equal(c1, c2) +}) # Additional tests to add # - Check various in scale and out scale combinations