Last active
January 30, 2021 15:23
-
-
Save hakimabdi/eadddfd66b05ffd8a9cb to your computer and use it in GitHub Desktop.
This function is for the installation and loading of R packages.. If an R package is not installed, the function will install it using the Austrian CRAN mirror (you can change that), and if a package is already installed, it will be loaded.
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
################################################################################################# | |
# title : pload.R | |
# purpose : Install and load uninstalled packages, or load installed ones. | |
# author : Abdulhakim Abdi (@HakimAbdi) | |
# input : Package name in quotes | |
# output : Installation and loading of uninstalled packages, or loading of installed ones. | |
################################################################################################# | |
pload <- function(x){ | |
if(x %in% rownames(installed.packages())) | |
#if (require(x,character.only = TRUE)) | |
require(x,character.only = TRUE) | |
else { | |
install.packages(x,dep=TRUE, repos="http://cran.at.r-project.org/") | |
require(x,character.only = TRUE) | |
} | |
} | |
## Example: | |
# pload("raster") | |
# pload("maptools") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment