Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions R/runCCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ",
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions tests/testthat/test-6cca.R
Original file line number Diff line number Diff line change
@@ -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)),
Expand Down
Loading