-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from nimarafati/master
Libraries installation in precourse
- Loading branch information
Showing
5 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
title: "Test installation of the packages" | ||
format: | ||
html: | ||
code-fold: true | ||
--- | ||
|
||
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'))}) | ||
} | ||
``` | ||
|