Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Fix condense() for ungrouped matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Jan 13, 2025
1 parent 1cdf75e commit d838091
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion R/condense.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ setMethod(
signature = "CompositionMatrix",
definition = function(x, by, verbose = FALSE, ...) {
x <- group(x, by = by)
methods::callGeneric(x = x, verbose = verbose, ...)
y <- methods::callGeneric(x = x, verbose = verbose, ...)
ungroup(y)
}
)

Expand Down
Binary file modified inst/tinytest/_snaps/condense.rds
Binary file not shown.
17 changes: 13 additions & 4 deletions inst/tinytest/test_condense.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
data("slides")
coda <- as_composition(slides, groups = 2)
coda <- as_composition(slides)

## Compositional mean by sample
## Ungrouped
flat <- condense(coda, by = slides$analyst)
expect_false(is_grouped(flat))
expect_identical(rownames(flat), paste0("A", 1:5))

## Compositional mean by group
coda <- group(coda, by = slides$analyst)
flat <- condense(coda)
expect_equal_to_reference(as.data.frame(flat), file = "_snaps/condense.rds")
expect_identical(group_names(flat), paste0("A", 1:5))

## Override groups
flat <- condense(coda, by = slides$analyst)
flat <- condense(coda, by = slides$slide)
expect_identical(rownames(flat), c("A", "B", "C", "D", "E"))
expect_identical(group_names(flat), rep(paste0("A", 1:5, collapse = ":"), 5))
expect_equal_to_reference(as.data.frame(flat), file = "_snaps/condense.rds")

## With zeros
X1 <- data.frame(
Expand Down

0 comments on commit d838091

Please sign in to comment.