R/allChecks.R

Defines functions is.singleLogical is.singleString is.singleInteger tal.checks

##This function is used for argument checking
tal.checks <- function(name, para){
    if(identical(name, "gg")) {
        if(!igraph::is.igraph(para)){
            stop("'gg' must be an igraph!", call.=FALSE)
        } else if (is.null(para$intnodes)){
            stop("'gg' must be created by phylo2igraph() 
                    or hclust2igraph()!", call.=FALSE)
        }
    } else if(identical(name, "theme")){
        if(!is.singleInteger(para) || para > 5 || para < 1){
            stop("'theme' must be an integer ranging from 1 to 5!", 
                    call.=FALSE)
        }
    } else if(identical(name, "cleanalias")){
        if(!is.singleLogical(para)){
            stop("'cleanalias' must be a logical value!", call.=FALSE)
        }
    } else if(identical(name, "obj")){
        if(!is(para, "RedPort")){
            stop("'obj' must be a RedPort object created by 
                    RedeR::RedPort()!", call.=FALSE)
        }
    } else if(identical(name, "phy")){
        if(!is(para, "phylo")){
            stop("'phy' must be a 'phylo' object!", call.=FALSE)
        }
    }
}


##------------------------------------------------------------------------------
is.singleInteger <- function(para){
    lg <- (is.integer(para) || is.numeric(para)) && length(para)==1L && 
        !is.na(para)
    if(lg) lg <- (para / ceiling(para)) == 1
    return(lg)
}
is.singleString <- function(para){
    is.character(para) && length(para) == 1L && !is.na(para)
}
is.singleLogical <- function(para){
    is.logical(para) && length(para) == 1L && !is.na(para)
}

Try the TreeAndLeaf package in your browser

Any scripts or data that you put into this service are public.

TreeAndLeaf documentation built on Nov. 8, 2020, 4:51 p.m.