I tend to use package managers for library load and management: pacman
With pacman::p_load() instead of 5 lines of code to load 5 common packages, like this:
library(dplyr) library(tidyr) library(Hmisc) library(magrittr) library(janitor)
You can write one line
pacman::p_load(dplyr, tidyr, Hmisc, janitor, magrittr)
if the package is not available on the system, it will first install it (through install.packages), and only then try to load it again. Same as library installr
All of this, on the very first part of any R file.