Skip to content

pgmj/RstudioQuartoIntro

Repository files navigation

Introduction to reproducible data analysis with R and Quarto

The materials made available here are not intended as a standalone educational product. The intended use scenario is with a course leader walking through the materials, adding information to what is on the slides and the data import/analysis files, and interacting with course participants.

With that said, you can browse the content and see if you find it useful. See the section Structure below.

Preparations

Install R (you need version 4.1 or later) for your platform:

Install the latest version of Rstudio, which includes Quarto:

Note: If you have an older version of R (not Rstudio) and need to upgrade, I find that the easiest way is to uninstall R and reinstall everything including packages from scratch. Unfortunately, it is not sufficient to use the regular uninstall functions, but you will find instructions on removal here: https://www.delftstack.com/howto/r/uninstall-r-and-all-its-packages-on-windows/

Rstudio settings

Start up Rstudio, and go to Tools -> Global options. In the window that appears, make sure your settings match those in the image below. You do not want to save or restore workspace .RData - ever.

Screenshot from Rstudio global options

If you like, you can change the visual theme under the Appearance tab.

Installing R packages

Below is a list of all the packages planned for use during the course. In Rstudio, in the bottom right quadrant (under the tab "Files"), create a "New Blank File" of type "R script". Then copy & paste the code below into the new file, or just run it from the Console tab in Rstudio.

install.packages(c("ggrepel","formattable","kableExtra","ggdist","ggrain",
                   "modelsummary","mice","GGally","easystats","patchwork",
                   "ggplot2","broom.mixed","nlme","lme4","psych","janitor",
                   "lubridate","skimr","car","styler","grateful","arrow","glue",
                   "showtext","readxl","foreign","tidyverse","visdat",
                   "gtsummary","scales","marginaleffects","ggeffects",
                   "sjPlot","haven"))

And for convenience here are the packages in another format, with some brief explanations.

# these are mostly for data management/wrangling and visualization
library(tidyverse) # for most things
library(haven) # for reading SPSS files and other formats
library(foreign) # also for reading SPSS files and other formats
library(readxl) # read MS Excel files
library(showtext) # get fonts
library(glue) # simplifies mixing text and code in figures and tables
library(arrow) # support for efficient file formats
library(grateful) # create table+references for packages used in a project
library(styler) # only a one-time installation (it is an Rstudio plugin)
library(car) # for car::recode only
library(skimr) # data skimming
library(lubridate) # for handling dates in data
library(janitor) # for many things in data cleaning

# these are mostly for data analysis and visualization
library(gtsummary)
library(scales)
library(visdat)
library(psych)
library(lme4) # linear mixed models
library(nlme) # non-linear models
library(broom.mixed) # get dataframe-formatted summaries of statistical models
library(ggplot2)
library(patchwork)
library(easystats) # lots of convenient statistical functions, see <https://easystats.github.io/>
library(GGally) # simple and nice correlation matrix
library(mice) # impute data
library(modelsummary) # easy summary of statistical models
library(ggrain) # raincloud plots
library(ggdist) # create plots of different distributions
library(kableExtra) # tables in different formats 
library(formattable) # tables in HTML format
library(ggrepel) # automatic flexible positioning of text to avoid overlap
library(marginaleffects)
library(ggeffects)
library(sjPlot)

Getting all the course files

There is a zip file with all the course files:

Make sure that you extract the zip file into a folder.

Note: Windows users beware of double-clicking the file since this may open the zip file in a way that looks like it already is a folder. Either right-click the file and select "Extract to..." or make sure to click the Extract button if you did double-click the file.

Using git

If you want to, you can to install Git and clone the repository instead. Download links: https://git-scm.com/downloads

Then you are going to "clone" this code repository to a folder on your computer. There are two ways to go about this. Either you start up a terminal/shell/command prompt and navigate to where you would like to put the folder (a subfolder will automatically be created) and run the command git clone https://github.com/pgmj/RstudioQuartoIntro.git, or you can use a graphical user interface for git. I have no experience with the GUI, so you will have to figure that out for yourself.

If you are new to navigating a file system with a terminal/shell/command prompt, here are some links that I hope are useful:

Structure

The core course files are the Quarto *.qmd files in the root directory of the repository. Rendered revealjs/HTML outputs from the .qmd files are available in the /docs folder and hosted with GitHub Pages. You can reach them directly at

All code is also available in the HTML-files. You should be able to re-create the HTML files from the .qmd files.

Credits

The datasets used: Mindfulness-integrated cognitive behaviour therapy (MiCBT) randomised controlled trial dataset.xlsx. (2020). [Data set]. Monash University. https://doi.org/10.26180/13240304

And for questionnaire item data: https://pgmj.github.io/PreventOSA/ With the data file available here: https://github.com/pgmj/PreventOSA/tree/main/data

Thanks to Emil Hvitfeldt for blog posts on revealjs design and the use of iframes.

Additional materials for the curious

It is not expected that you look at these before starting the course.

Author

Magnus Johansson is a licensed psychologist with a PhD in behavior analysis from Oslo Metropolitan University. He works as a research scientist at RISE Research Institutes of Sweden, Department of System Transition, and is an affiliated researcher at Karolinska Institutet.

License

This work is licensed under the MIT License.

About

A brief intro course on reproducible data analysis with Quarto and R

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published