Created
April 27, 2022 10:18
-
-
Save andrewmoles2/e52307e0296955067e50a6651aa935d0 to your computer and use it in GitHub Desktop.
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
# function to check install and load packages | |
load_library <- function(pkg) { | |
# check if package is installed | |
new_package <- pkg[!(pkg %in% installed.packages()[, "Package"])] | |
# install any new packages | |
if (length(new_package)) | |
install.packages(new_package, dependencies = TRUE, Ncpus = 6) | |
# sapply to loop through and load packages | |
invisible(sapply(pkg, library, character.only = TRUE)) | |
# give message confirming load | |
message("The following packages are now loaded") | |
print(names(sessionInfo()$otherPkgs)) | |
} | |
# use test | |
packages <- c('tidyverse', 'report', 'tidytext', 'data.table') | |
load_library(packages) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment