Skip to content

Commit

Permalink
make the check for k isn't zero after validate qsvPCs is a prcomp object
Browse files Browse the repository at this point in the history
  • Loading branch information
HediaTnani committed Jan 12, 2024
1 parent c11276f commit f0ca55c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions R/get_qsvs.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
#' qsv <- list(x = matrix(seq_len(9), ncol = 3))
#' get_qsvs(qsv, 2)
get_qsvs <- function(qsvPCs, k) {
# check that k isn't zero
if (k <= 0 | k > ncol(qsvPCs$x)) {
stop(paste("k must between 1 and",ncol(qsvPCs$x)))
}

# Validate qsvPCs is a prcomp object
if (!is(qsvPCs, "prcomp")) {
stop("qsvPCs must be a prcomp object.", call. = FALSE)
}

# check that k isn't zero
if (k <= 0 | k > ncol(qsvPCs$x)) {
stop(paste("k must between 1 and",ncol(qsvPCs$x)))
}

qSVs <- qsvPCs$x[, seq_len(k), drop = FALSE]
colnames(qSVs) <- paste0("qSV", seq_len(k))
return(qSVs)
Expand Down

0 comments on commit f0ca55c

Please sign in to comment.