R/inst.if.R

Defines functions inst.if

Documented in inst.if

#' Install and load packages if necessary
#' 
#' This function checks to see if a package is installed yet
#' If not, it installs it.  Either way, once installed, it loads the library.
#' @param pkgname The name of the desired package as a string
#' @export
#' @examples
#' inst.if("Matrix")
#' 
inst.if <- function(pkgname){
    #Install if not in the list of available packages
    if (!require(pkgname, character.only=TRUE)) { 
        install.packages(eval(pkgname)) 
    }
    #Load
    library(pkgname, character.only=TRUE)
}
lcomm/ltools documentation built on May 20, 2019, 11:28 p.m.