diff --git a/R/plotArrow.R b/R/plotArrow.R index a6a6e614..d85f90f3 100644 --- a/R/plotArrow.R +++ b/R/plotArrow.R @@ -70,7 +70,11 @@ plotArrow <- function(object, object.blocks=c("sgcca", "sgccda", "rgcca") if (! any(class.object %in% c(object.pls,object.blocks))) - stop( " 'plotArrow' is only implemented for the following objects: pls, plsda, spls, splsda, rcc, sgcca, sgccda, rgcca", call.=FALSE) + stop( " 'plotArrow' is only implemented for the following objects: pls, spls, rcc, sgcca, sgccda, rgcca", call.=FALSE) + + if ("DA" %in% class.object && !any(object.blocks %in% class.object)) { + stop("'plotArrow' not implemented for (s)PLSDA or MINT sPLSDA", call.=FALSE) + } ind.names.position <- match.arg(ind.names.position) is.multiblock <- ifelse(is.list(object$X), TRUE, FALSE) diff --git a/tests/testthat/test-plotArrow.R b/tests/testthat/test-plotArrow.R new file mode 100644 index 00000000..3b427e7b --- /dev/null +++ b/tests/testthat/test-plotArrow.R @@ -0,0 +1,38 @@ +test_that("plotArrow does not function on (mint).(s).plsda objects", code = { + + data("stemcells") + + X <- stemcells$gene + Y <- stemcells$celltype + S <- stemcells$study + + optimal.ncomp <- 4 + optimal.keepX <- c(24, 45, 20, 30) + + splsda.stemcells <- splsda(X = X, Y = Y, + ncomp = optimal.ncomp, + keepX = optimal.keepX) + expect_error(plotArrow(splsda.stemcells), "'plotArrow' not implemented for (s)PLSDA or MINT sPLSDA", fixed = TRUE) +}) + +test_that("plotArrow functions on DIABLO objects", code = { + + data(breast.TCGA) + + X <- list(miRNA = breast.TCGA$data.train$mirna, + mRNA = breast.TCGA$data.train$mrna, + proteomics = breast.TCGA$data.train$protein) + Y <- breast.TCGA$data.train$subtype + + optimal.ncomp <- 2 + optimal.keepX <- list(miRNA = c(10, 5), + mRNA = c(25,16), + proteomics = c(8,5)) + tcga.diablo <- block.splsda(X, Y, + ncomp = optimal.ncomp, + keepX = optimal.keepX) + + pA_res <- plotArrow(tcga.diablo) + + expect_is(pA_res, "ggplot") +}) \ No newline at end of file