Created
October 9, 2013 14:05
-
-
Save timvink/6901856 to your computer and use it in GitHub Desktop.
Test whether package is installed. If not, install. Then Load. example use: pkgTest("ggplot2") instead of normal library("ggplot2").
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
pkgTest <- function(x) | |
{ | |
if (!require(x,character.only = TRUE)) | |
{ | |
install.packages(x,dep=TRUE, repos="http://cran-mirror.cs.uu.nl/") | |
if(!require(x,character.only = TRUE)) stop("Package not found, cannot be installed") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment