diff --git a/R/runCCA.R b/R/runCCA.R index 5e9f47d32..af2ba2446 100644 --- a/R/runCCA.R +++ b/R/runCCA.R @@ -480,9 +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 <- .remove_special_functions_from_terms(terms) + terms <- formula |> terms() |> delete.response() |> all.vars() # 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 ", @@ -493,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 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)),