Skip to content

Instantly share code, notes, and snippets.

@mrecos
Created October 20, 2015 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrecos/889e301c7ce4a3c4f960 to your computer and use it in GitHub Desktop.
Save mrecos/889e301c7ce4a3c4f960 to your computer and use it in GitHub Desktop.
R Package Loader
load.fun <- function(x) {
x <- as.character(x)
if(isTRUE(x %in% .packages(all.available=TRUE))) {
eval(parse(text=paste("require(", x, ")", sep="")))
print(paste(c(x, " : already installed; requiring"), collapse=''))
} else {
if(x == "twitteR"){
print(paste(c(x, " : not installed; installing"), collapse=''))
install_github("twitteR", username="geoffjentry")
print(paste(c(x, " : installed and requiring"), collapse=''))
eval(parse(text=paste("require(", x, ")", sep="")))
} else {
#update.packages()
print(paste(c(x, " : not installed; installing"), collapse=''))
eval(parse(text=paste("install.packages('", x, "')", sep="")))
print(paste(c(x, " : installed and requiring"), collapse=''))
eval(parse(text=paste("require(", x, ")", sep="")))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment