How install Multiple libraries in R?

Many times when executing a code, we have to install and load the necessary libraries for that it works correctly.

Today I want to show you a simple solution so that with just one function and three lines of code you can create a preload for your Apps.

For this we are going to create the loadapp function, in which we will include the following code:

loadApp <- function(){

#Load the libraries we need:
load.lib<-c("footballR", "dplyr","skellam","ggplot2","purrr","tidyr")
#We create a variable where we indicating that we select the ones that we do not have installed.                     
install.lib <- load.lib[!load.lib %in% installed.packages()]
# With a loop we install the libraries we don't have.
for(lib in install.lib) install.packages(lib,dependences=TRUE)
#Load the libraries
sapply(load.lib,require,character=TRUE)
}

Now every time you want to load all the libraries of your application in a simple way, you just have to call this function, I hope it will help you.

loadApp()


Summary
How install Multiple libraries in R?
Article Name
How install Multiple libraries in R?
Description
How to create a script that load multiple libraries in R and check what libraries you don't have, you can use this script to help you to do this.
Author
Publisher Name
Blog-R
Publisher Logo

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *