Please knit this document. # Installing the packages ```{r install, include = TRUE, warning=FALSE, message=FALSE} # List of packages to install packages <- c('rmarkdown', 'fontawesome', 'bookdown', 'htmltools', 'knitr', 'leaflet', 'yaml', 'stringr', 'renv', 'dplyr', 'lubridate', 'formattable', 'kableExtra', 'tidyr', 'ggplot2', 'readxl', 'nycflights13', 'xaringan', 'vcd', 'patchwork', 'tibble', 'markdown', 'magrittr', 'tidyverse') # Function to check if packages are installed, and install missing ones install_if_missing <- function(pkg) { if (!requireNamespace(pkg, quietly = TRUE)) { install.packages(pkg, dependencies = TRUE, repos = "https://cloud.r-project.org") } } # Loop through the packages and install any that are missing sapply(packages, install_if_missing) ``` # Check the installation ```{r test, include = TRUE} # Check if all packages are installed installed <- 0 installed_packages <- sapply(packages, function(pkg) { if (requireNamespace(pkg, quietly = TRUE)) { return(1) } else { return(paste(pkg, "is NOT installed.")) } }) # Print the installation status of each package if (sum(!is.na(installed_packages)) == length(packages)){ print('Congratulations you have installed all the packages') }else{ sapply(names(installed_packages[is.na(installed_packages)]), function(pkg){print(paste0('Package ', pkg, ' is not installed'))}) } ```