diff --git a/R/qSVA.R b/R/qSVA.R index 3b958f9..27c9150 100644 --- a/R/qSVA.R +++ b/R/qSVA.R @@ -42,7 +42,14 @@ qSVA <- assayname) { ## We don't need to pass type to getDegTx() since it's not used internally ## once the sig_transcripts have been defined. - DegTx <- + + # Check if assayname is in assayNames + if (!assayname %in% assayNames(rse_tx)) { + stop(sprintf("'%s' is not in assayNames(rse_tx).", assayname), call. = FALSE) + } + + # Get the qSVs + DegTx <- getDegTx(rse_tx, sig_transcripts = sig_transcripts, assayname = assayname) PCs <- getPCs(DegTx, assayname) k <- k_qsvs(DegTx, mod = mod, assayname = assayname) diff --git a/tests/testthat/test-qSVA.R b/tests/testthat/test-qSVA.R index 99544e9..1288c22 100644 --- a/tests/testthat/test-qSVA.R +++ b/tests/testthat/test-qSVA.R @@ -22,3 +22,8 @@ test_that("output is a matrix", { test_that("output is an array", { expect_equal(class(qsva_cc)[2], "array") }) + +# Test for assayname not in assayNames +test_that("qSVA throws an error when assayname is not in assayNames", { + expect_error(qSVA(covComb_tx_deg, type = "standard", mod = mod,assayname = "not_in_assayNames"), "'not_in_assayNames' is not in assayNames\\(rse_tx\\).") +}) \ No newline at end of file