Skip to content

Commit

Permalink
Merge pull request #13 from nimarafati/master
Browse files Browse the repository at this point in the history
Libraries installation in precourse
  • Loading branch information
nimarafati authored Oct 22, 2024
2 parents cd7891d + 31d08ae commit fec95de
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
Binary file added Test_Installation.mov
Binary file not shown.
22 changes: 19 additions & 3 deletions home_precourse.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,26 @@ Go to [r-project.org](https://cloud.r-project.org/) and choose the link appropri

RStudio provides you with tools like code editor with highlighting, project management, version control, package building, debugger, profiler and more. Start up RStudio to check that everything has been installed correctly. If not, contact us and we can help you out.

You can also watch [this video](https://youtu.be/suX6nsSUXDw?si=FbaiaCpRNvtjxt5N) for an introduction to using RStudio

`r fa1("chevron-circle-right")`   **Install R packages**

Extra R packages used in the workshop exercises (if any) are listed below. It is recommended that you install this in advance. Simply copy and paste the code into R.
Please download this [test_installation.Rmd file](../test_installation.Rmd) and Knit/Render it by clicking on the knit/render icon on the upper right of R Studio or by navigating to file > knit document.
After rendering if everything goes well you should see this message towards end of the rendered html file:

- **Congratulations you have installed all the packages**.

If there are any missing packages they will be printed at the end of the rendered html file.


```{r include=FALSE}
<video width="640" height="480" controls>
<source src="../Test_Installation.mov" type="video/mp4">
Your browser does not support the video tag.
</video>

<!-- Extra R packages used in the workshop exercises (if any) are listed below. It is recommended that you install this in advance. Simply copy and paste the code into R. -->

```{r , echo = F, eval = F}
# this first chunk runs through the root directory, finds the installed packages across the files and prints them as installation instruction.
#Add to the pkg_discard object the packages you want to discard from the list
Expand All @@ -78,7 +93,7 @@ pkg_list<-pkg[!pkg %in% pkg_discard]
```

```{r echo=FALSE, warning=FALSE, chunk.title=NULL, class.output="r", comment="", r,eval=TRUE}
```{r echo=FALSE, warning=FALSE, chunk.title=NULL, class.output="r", comment="", r,eval=FALSE}
cat("# install from cran\n")
cat(paste0("install.packages(c('",paste(pkg_list,sep="",collapse="','"),"'))"))
Expand All @@ -87,6 +102,7 @@ pkg_list<-pkg[!pkg %in% pkg_discard]
```


`r fa1("chevron-circle-right")` &nbsp; **Install Docker**

It is NOT absolutely necessary to have Docker installed, but we are working on shipping the working course as a Docker container ready to run. In order to be able to use this functionality, please make sure you have [Docker Desktop](https://www.docker.com/get-started) installed and running on your machine.
Expand Down
4 changes: 2 additions & 2 deletions schedule.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ date;room;start_time;end_time;topic;teacher;assistant;link_slide;link_lab;link_r
;;12:00;13:00;Lunch;;;;;
;;13:00;15:00;Loading data into R;Guilherme;;;lab_loadingdata.html;
;;15:00;15:30;Essential: Basic statistics;Nima;;slide_r_basic_statistic.html;;
;;15:30;16:00;Essential: Basic statistics;Nima;;;;
;;15:30;16:00;Essential: Basic statistics;Nima;;;lab_statistics.html;
;;16:00;17:00;Group discussion on projects;;;;;
30/10/2024;Experimental room;09:00;10:00;Essential: Loops, Conditionals, Functions;Miguel;;slide_r_elements_4.html;;
;;10:00;12:00;Essential: Loops, Conditionals, Functions;Miguel;;;lab_loops.html;
Expand All @@ -34,4 +34,4 @@ date;room;start_time;end_time;topic;teacher;assistant;link_slide;link_lab;link_r
;;11:00;12:00;Group discussion on projects;;;;;
;;12:00;13:00;Lunch;;;;;
;;13:00;14:30;Group presentation;;;;;
;;14:30;15:00;Q & A;;;;;
;;14:30;15:00;Q & A;;;;;
2 changes: 1 addition & 1 deletion slide_r_intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ name: pkg_cran_inst
Only a few packages are pre-installed:

```{r pkg.err.ex,eval=TRUE,error=TRUE}
library(XLConnect)
library(modelr)
```

In order to install a package from command line, use:
Expand Down
49 changes: 49 additions & 0 deletions test_installation.Rmd
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'))})
}
```

0 comments on commit fec95de

Please sign in to comment.