I found this post on how to install and load missing packages, which was helpful. However, I was wondering if I always have to write out the packages or if you somehow can do this when the code contains a list of "library()" like this:
library(ggplot2)
library(rugarch)
library(PortfolioAnalytics)
library(tidyverse)
Because that's how it usually looks like when someone is sharing code with you and it'd be great if it was possible to simply write some code around it and not having to copy-paste every package name into the appropriate code.