Last active
August 29, 2015 13:56
-
-
Save garyfeng/a51ac94d857c5f58d501 to your computer and use it in GitHub Desktop.
r code to test and install libraries if not already installed.
This file contains hidden or 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
# r code to test and install libraries if not already installed. | |
# code taking from stackoverflow | |
pkgInstall <- function(x) | |
{ | |
if (!require(x,character.only = TRUE)) | |
{ | |
install.packages(x,dep=TRUE) | |
if(!require(x,character.only = TRUE)) stop("Package not found") | |
} | |
library(x, character.only = TRUE) | |
} | |
# examples | |
# pkgInstall("TraMineR") | |
# pkgInstall("TraMineRextras") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
current version loads the library immediately, to save some commands. There are cases where you may not want that. Just comment out this line.