Skip to content

Instantly share code, notes, and snippets.

@gyli
Last active August 29, 2015 14:06
Show Gist options
  • Save gyli/75f6443614e653cdcbcb to your computer and use it in GitHub Desktop.
Save gyli/75f6443614e653cdcbcb to your computer and use it in GitHub Desktop.
Package loading in R (Check if installed before loading)
pkg.install <- function(x)
{
if (!require(x,character.only = TRUE))
{
install.packages(x,dep=TRUE)
if(!require(x,character.only = TRUE)) stop("Package not found")
}
}
pkg.install("DBI")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment