From 2875cfa149260264819dc696791645e3b747b852 Mon Sep 17 00:00:00 2001 From: Tuomas Borman Date: Wed, 29 Jul 2026 13:58:42 +0300 Subject: [PATCH 1/3] fix formula parsing --- R/runCCA.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/runCCA.R b/R/runCCA.R index 5e9f47d32..6aadbb2a7 100644 --- a/R/runCCA.R +++ b/R/runCCA.R @@ -480,8 +480,7 @@ setMethod("addRDA", "SingleCellExperiment", "'col.var' and leave 'formula' unspecified.", call. = FALSE) } # Get variables from formula - terms <- rownames(attr(terms(formula), "factors")) - terms <- terms[terms != as.character(formula)[2L]] + terms <- formula |> terms() |> delete.response() |> all.vars() terms <- .remove_special_functions_from_terms(terms) # Check that all variables specify a column from colData if( !all(terms %in% colnames(colData(x))) ){ From ecefa0049f565d785a10960f04775599d8a151dd Mon Sep 17 00:00:00 2001 From: Tuomas Borman Date: Wed, 29 Jul 2026 14:02:34 +0300 Subject: [PATCH 2/3] up --- R/runCCA.R | 1 - tests/testthat/test-6cca.R | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/R/runCCA.R b/R/runCCA.R index 6aadbb2a7..29ff9217d 100644 --- a/R/runCCA.R +++ b/R/runCCA.R @@ -481,7 +481,6 @@ setMethod("addRDA", "SingleCellExperiment", } # Get variables from formula terms <- formula |> terms() |> delete.response() |> all.vars() - terms <- .remove_special_functions_from_terms(terms) # Check that all variables specify a column from colData if( !all(terms %in% colnames(colData(x))) ){ stop("All variables on the right hand side of 'formula' must be ", diff --git a/tests/testthat/test-6cca.R b/tests/testthat/test-6cca.R index 470968be4..db9878a0a 100644 --- a/tests/testthat/test-6cca.R +++ b/tests/testthat/test-6cca.R @@ -1,17 +1,5 @@ context("CCA") test_that("CCA", { - # .remove_special_functions_from_terms - expect_error(mia:::.remove_special_functions_from_terms(), - 'argument "terms" is missing, with no default') - expect_equal(mia:::.remove_special_functions_from_terms("abc"), - c(abc = "abc")) - expect_equal(mia:::.remove_special_functions_from_terms("Condition(abc)"), - c("Condition(abc)" = "abc")) - expect_equal(mia:::.remove_special_functions_from_terms(c("abc","def")), - c(abc = "abc", def = "def")) - expect_equal(mia:::.remove_special_functions_from_terms(c("Condition(abc)","def")), - c("Condition(abc)" = "abc", def = "def")) - # skip_if_not(requireNamespace("vegan", quietly = TRUE)) data(dune, dune.env, package = "vegan") sce <- SingleCellExperiment(assays = list(counts = t(dune)), From 868ec2da00ac1647695880ad6c2e332430cc13d6 Mon Sep 17 00:00:00 2001 From: Tuomas Borman Date: Wed, 29 Jul 2026 14:03:45 +0300 Subject: [PATCH 3/3] up --- R/runCCA.R | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/R/runCCA.R b/R/runCCA.R index 29ff9217d..af2ba2446 100644 --- a/R/runCCA.R +++ b/R/runCCA.R @@ -491,20 +491,6 @@ setMethod("addRDA", "SingleCellExperiment", return(df) } -# This function parses right-hand side formula so that it now includes only -# the covariates. -.remove_special_functions_from_terms <- function(terms){ - names(terms) <- terms - m <- regexec("^Condition\\(([^\\(\\)]*)\\)$|^([^\\(\\)]*)$", terms) - m <- regmatches(terms, m) - terms <- vapply(m, function(n){ - n <- n[seq.int(2L,length(n))] - n <- n[n != ""] - return(n) - }, character(1)) - return(terms) -} - # This function performs dbRDA or CCA. It returns side scores with other # information scores in attributes. #' @importFrom stats as.formula na.fail