An R package of learnr tutorials for R and biostats

tl;dr I made an R package called biostats.tutorials containing learnr tutorials on R and stats. Available on GitHub.

Learning statistics and R has changed a lot since I started in undergrad and that wasn’t that long ago. When I learnt it, it was basic. The lecturers chose not to use RStudio so we used the basic R interface and copied and pasted to notepad if we wanted to save what we did. Simpler times.

These days there lots of tutorials and worksheets that are a google search away. One of these newer tools is the package learnr which creates interactive tutorials based on shiny. learnr tutorials have been integrated into RStudio so that they show up under a “Tutorials” tab. I think that’s a huge development because it opens up the accessibility and ease of use of these tutorials. So I decided to check it out…

Overall structure

A learnr tutorial is a Rmarkdown file that has some background shiny element. I won’t go into too much detail. The learnr documentation is pretty comprehensive so I’ll only be brief here: https://rstudio.github.io/learnr/

Like a regular Rmarkdown file you can mix text and code chunks. What’s different are code exercises and questions.

Coding exercises

learnr allows interactive code chunks that can be filled in with coding exercises for people to do. These blocks can be executed and shows the R output. You can include hints and solutions and make it timed. Code in these blocks are independent of the R environment so they don’t get saved.

Questions

There are different types of questions supported such as single choice MCQ or multiple choice MCQ or text entry.

The text entry questions can accept numbers or characters, but when you define the answer in the code it needs to be a character vector.

There is also support for LaTeX notation. I found the paste0 function useful for combining R variables with strings.

Distributing tutorials

Single tutorials can be sent around but a series of tutorials can be packaged and distributed via Github for example.

I created a few tutorials based on scripts that I would give to my students that accompany my lecture. These are available on my GitHub in a package called biostats.tutorials. This is very much in development but I would appreciate any feedback on them if you use them.

Impressions

Overall I think this is promising for teaching R and statistics though it does represent a considerable investment into developing teaching material. Having interactive coding exercises can help students engage with the concepts better and promotes active learning. However, I think the real judge of whether theses interactive tutorials are better or engaging are the students. I will have to find some test subjects…

Leave a comment