Skip to content

Edits to CreateCategoryMatrix for colon groups#10399

Open
mccormickceci wants to merge 1 commit into
mainfrom
fix/preserve_colons_in_aggregate_expr
Open

Edits to CreateCategoryMatrix for colon groups#10399
mccormickceci wants to merge 1 commit into
mainfrom
fix/preserve_colons_in_aggregate_expr

Conversation

@mccormickceci

Copy link
Copy Markdown
Contributor

Summary

Type of change

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (existing functionality changed or removed)
  • Documentation update
  • Other (please explain below)

Motivation

In the case that users were aggregating on a metadata variable containing a colon the colon would not be preserved in the result because we use colons inside of the CreateCategoryMatrix to split by groups.

Tests & examples

library(SeuratData)
library(Seurat)

pbmc_small$letter.idents <- paste0('anything:', pbmc_small$letter.idents)
head(pbmc_small$letter.idents)
result <- AggregateExpression(pbmc_small, assays = 'RNA', group.by = 'letter.idents')$RNA
head(result)

Related issues

This should fix the issue as it relates to #9137
Closes #9137

Checklist

  • Branch is named appropriately (feat/*, fix/*, docs/*)
  • Code follows Seurat style guidelines
  • Documentation and comments have been updated
  • devtools::document() has been run
  • devtools::check() passes with no errors or warnings
  • Test case demonstrating new functionality is included
  • Maintainers are allowed to edit this PR

Copilot AI review requested due to automatic review settings May 22, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes loss of : characters in aggregated group names by adjusting how CreateCategoryMatrix() post-processes column names when only a single grouping variable is used (the : is currently overloaded as an interaction separator).

Changes:

  • Preserve : characters in group labels when CreateCategoryMatrix() is called with a single grouping column.
  • Minor whitespace cleanup in a warning call formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/utilities.R
Comment on lines 3109 to +3112
FUN = function(name) {
name <- gsub(pattern = "data\\[, [1-9]*\\]", replacement = "", x = name)
if (length(group.by) == 1) {
return(name)
Comment thread R/utilities.R
Comment on lines +3111 to 3115
if (length(group.by) == 1) {
return(name)
}
return(paste0(rev(x = unlist(x = strsplit(x = name, split = ":"))), collapse = "_"))
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Identity names with colons are not handled appropriately by AggregateExpression()

2 participants