Skip to content

Commit

Permalink
Updated fix for Issue #120
Browse files Browse the repository at this point in the history
test: added test case for `mint.(s)pls` in `test-plotLoadings.R` to ensure coverage of diff

also adjusted `is()` calls to `inherits()` to see if this solves `vignette.Rmd` issue - unlikely
  • Loading branch information
Max-Bladen committed May 17, 2022
1 parent 5e9baa9 commit ea15024
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 7 additions & 7 deletions R/plotLoadings.R
Original file line number Diff line number Diff line change
Expand Up @@ -967,10 +967,10 @@ check.input.plotLoadings <- function(object,
# --
if (missing(block))
{
if (!is(object, "DA"))
if (!inherits(object, "DA"))
{
block = object$names$blocks
} else if (is(object, c("mixo_plsda", "mixo_splsda"))) {
} else if (inherits(object, c("mixo_plsda", "mixo_splsda"))) {
block = "X"
} else {
if (!is.null(object$indY))
Expand All @@ -982,17 +982,17 @@ check.input.plotLoadings <- function(object,
}
}

if (is(object, c("mixo_plsda", "mixo_splsda")) & (!all(block %in% c(1,"X")) | length(block) > 1 ))
if (inherits(object, c("mixo_plsda", "mixo_splsda")) & (!all(block %in% c(1,"X")) | length(block) > 1 ))
stop("'block' can only be 'X' or '1' for plsda and splsda object")

if (is(object, c("mixo_plsda", "mixo_splsda","pca")))
if (inherits(object, c("mixo_plsda", "mixo_splsda","pca")))
{
object$indY = 2
} else if (is(object, c("mixo_pls", "mixo_spls"))) {
} else if (inherits(object, c("mixo_pls", "mixo_spls"))) {
object$indY = 3 # we don't want to remove anything in that case, and 3 is higher than the number of blocks which is 2
}

if(!is(object, "DA"))
if(!inherits(object, "DA"))
object$indY = length(object$names$blocks)+1 # we don't want to remove anything in that case, and 3 is higher than the number of blocks which is 2

if(is.numeric(block))
Expand Down Expand Up @@ -1203,7 +1203,7 @@ get.loadings.ndisplay <- function(object,

#comp
# ----
if (is(object, c("mixo_pls","mixo_spls", "rcc")))# cause pls methods just have 1 ncomp, block approaches have different ncomp per block
if (inherits(object, c("mixo_pls","mixo_spls", "rcc")))# cause pls methods just have 1 ncomp, block approaches have different ncomp per block
{
ncomp = object$ncomp
object$X = list(X = object$X, Y = object$Y) # so that the data is in object$X, either it's a pls or block approach
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-plotLoadings.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ test_that("plotLoadings.mint.splsda works", code = {

})


test_that("plotLoadings.mint.spls works", code = {
data(stemcells)
samples <- c(1:5,60:64)
X <- stemcells$gene[samples, 1:10]
Y <- stemcells$gene[samples+5, 1:10]
S <- as.character(stemcells$study[samples])

res = mint.spls(X = X, Y = Y, ncomp = 3,
keepX = seq(3, 9, 3),
keepY = seq(3, 9, 3),
study = S)
pl_res <- plotLoadings(res, contrib = "max")

expect_is(pl_res, "list")
})


test_that("plotLoadings margin errrors is handled properly", code = {
data(nutrimouse)
Y = nutrimouse$diet
Expand Down

0 comments on commit ea15024

Please sign in to comment.