Created
August 14, 2013 13:36
-
-
Save daviosa/6231143 to your computer and use it in GitHub Desktop.
Function to require a R package and install it if needed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require.install <- function(pkg, github=""){ | |
req <- suppressWarnings( | |
suppressMessages( | |
require(package=paste(pkg), character.only=TRUE) | |
) | |
); | |
#print(github); | |
if(!req){ | |
installOk <- FALSE; | |
if(length(github)<=0){ | |
suppressWarnings( | |
suppressMessages( | |
install.packages(paste(pkg),dep=TRUE) | |
) | |
); | |
installOk <- TRUE; | |
}else if(length(github)>0){ | |
if(suppressWarnings( | |
suppressMessages( | |
require("devtools") | |
) | |
) | |
){ | |
suppressWarnings( | |
suppressMessages( | |
install_github(paste(pkg),paste(github)) | |
) | |
); | |
installOk <- TRUE; | |
} | |
} | |
if(installOk){ | |
suppressWarnings( | |
suppressMessages( | |
require(package=paste(pkg), character.only=TRUE) | |
) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment