Created
January 21, 2022 14:22
-
-
Save Godrigos/c6faaa0c2d2541dc8eb0e6b0d1b2b963 to your computer and use it in GitHub Desktop.
Check if required R packages are installed, and load them.
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
## If a package is installed, it will be loaded. If any | |
## are not, the missing package(s) will be installed | |
## from CRAN and then loaded. | |
## First specify the packages of interest | |
packages = c("tidyverse", "geomorph", | |
"phytools", "viridis") | |
## Now load or install & load all | |
package.check <- lapply( | |
packages, | |
FUN = function(x) { | |
if (!require(x, character.only = TRUE)) { | |
install.packages(x, dependencies = TRUE) | |
library(x, character.only = TRUE) | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment