Skip to content

Instantly share code, notes, and snippets.

@rpietro
Forked from daviosa/require.install.package.R
Created August 15, 2013 00:17
Show Gist options
  • Save rpietro/6237125 to your computer and use it in GitHub Desktop.
Save rpietro/6237125 to your computer and use it in GitHub Desktop.
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