This workshop is delivered in 6 modules and aims to get the user comfortable with basic R. It goes through installing R and Rstudio, learning about operators and data structures, functions, packages, and basics of data manipulation, including with dplyr, tidyr and visualisation with ggplot2.
No knowledge requirements. To go through with the workshop, R version 4.0+ and Rstudio must be installed. Installation of R, RStudio and necessary packages are helped with in the slides and scripts. Please review the following topics if you're not comfortable with them:
- basic linear algebra (operations with vectors and metrices)
- mathematical operations (exponentials, logarithms)
- basic statistics (mean, variance, median, standard deviation)
- logical statements (AND, OR, NOT)
- [R] (https://cran.rstudio.com/)
- [RStudio] (https://posit.co/download/rstudio-desktop/)
Slides can be found here.
In the first module of the workshop, the goals are to familiarize with the language and the logic behind it; Get started with R studio and create your first project; Create your first .R
file to write down the live code; and get comfortabble with installing packages.
Module content:
- Seeking help
- Installing packages
In this section participants will understand the differences between classes, objects and data types in R; Compute arithmetic operations; Use logical operators; create objects of different types, learn about their attributes and apply some built-in functions in R; Subset and index objects; and get comfortable with vectorized operations.
Module content:
- Vectors
- Lists
- Factors
- Data frames
- Arrays
- Coercion
In this module, participants learn to use if-else, while, and for loops; as well as building their own functions; and what packages are.
Module Content
- If..Else
- While loop
- For loop
- Functions
- Packages
In this module participants will learn how to read/write data to/from files with different formats (.tsv, .csv); become familiar with basic data-frame operations; (3) index and subset data frames using base R; manipulate individual data frame columns.
Module content:
- Reading/writing data
- Exploring data frames
The fourth module participants will familiarize with the dplyr syntax; create pipes with the operator %>%
; perform operations on data frames using dplyr and tidyr functions; learn how to join columns and rows of different data frames; and implement functions from external packages by reading their documentation in R.
Module content:
- Handling data frames with dplyr
- Other useful packages
- Hands-on: advanced data manipulation
This section will show participants how to (1) Create basic plots using base R functions; (2) Understand how to connect data frames with ggplot2; (3) create basic graphs with ggplot2; (4) use factors to customize graphics in ggplot2; (5) use RMarkdown to generate customized reports.
Module content:
- Figures with base R
- Graphics with
ggplot2
├── README.md
├── .gitignore
├── _config.yaml
├── IntroToR.Rproj
├── Exercises
│ └── README.md
│ ├── data
│ │ └── co2_pcap_cons.csv
│ │ └── penguins.csv
│ ├── scripts
│ │ └── 01GettingStarted.Rmd and .html
│ │ └── 02DataTypes.Rmd and .html
│ │ └── 03ControlStructuresAndFunctions.Rmd and .html
│ │ └── 04BasicDataManipulation.Rmd and .html
│ │ └── 05AdvancedDataManipulation.Rmd and .html
│ │ └── 06GeneratingOutputs.Rmd and .html
├── Slides
│ └── IntroToR_CBHWorkshop.pptx
└── Outline
└── workshopoutline.pdf #using the template provided
The materials for this workshop were based on the following sources:
Data in this workshop comes from:
- Horst AM, Hill AP, Gorman KB (2020). palmerpenguins: Palmer Archipelago (Antarctica) penguin data. R package version 0.1.0. https://allisonhorst.github.io/palmerpenguins/. doi: 10.5281/zenodo.3960218
- Gapminder data free from www.gapminder.org, CC-BY LICENSE
- Bryan J (2025). gapminder: Data from Gapminder. doi:10.32614/CRAN.package.gapminder https://doi.org/10.32614/CRAN.package.gapminder, R package version 1.0.1, https://CRAN.R-project.org/package=gapminder.
- Higgins P (2021). medicaldata: Data Package for Medical Datasets. doi:10.32614/CRAN.package.medicaldata https://doi.org/10.32614/CRAN.package.medicaldata, R package version 0.2.0, https://CRAN.R-project.org/package=medicaldata.
Workshop created as part of the McGill Initiative in Computational Medicine