R/preProcessing.R

Defines functions preCheck

#' @include generics.R
#'
NULL

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Functions
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

preCheck <- function(X=X, Z0=Z0, Y=Y, num.X = num.X, num.Y = num.Y, num.iteration = num.iteration,
        temp.path = temp.path, tolerance = tolerance, save = save, bigMemory = bigMemory,
        block.size = block.size, ncore = NCORES){

    if (!is.matrix(X) && !is.sparseMatrix(X)){
        stop("Please input X as a matrix!")
    }
    if (!is.matrix(Z0) && !is.sparseMatrix(Z0)){
        stop("Please input Z0 as a matrix!")
    }
    if (!is.matrix(Y) && !is.sparseMatrix(Y)){
        stop("Please input Y as a matrix!")
    }

    if(dim(X)[1]!=dim(Z0)[1]){
        stop("X and Z0 should have the same row number!")
    }
    if(dim(Z0)[2]!=dim(Y)[2]){
        stop("Z0 and Y should have the same column number!")
    }
    tp <- min(dim(X)[2], dim(Z0)[2])
    if(!all.equal(num.X, as.integer(num.X)) || num.X<0 || num.X >tp){
        stop(paste("The num.X should be integer ranging from 2 to", tp))
    }

    tp <- min(dim(Z0)[1], dim(Y)[1])

    if(!all.equal(num.Y, as.integer(num.Y)) || num.Y<0 || num.Y >tp){
        stop(paste("The num.Y should be integer ranging from 2 to", tp))
    }

    if(save && is.null(temp.path)){
    	stop("Please specify the folder to store temporary output")
    }
    return(TRUE)
}
jinzhuangdou/SCCAT documentation built on July 8, 2020, 2:36 p.m.