All quiz questions in the lectures have been now converted into a swirl course so that students can answer the quiz questions directly from within R, without all the additional information shown in the slides. The course is similarly structured as the lectures, containing 13 lessons each representing quizzes of one lecture. You will notice that the more advanced programming, visualization and modelling lectures are not included in the swirl course. The exercises in these lectures require more complex code snippets, which is less suited for the 1-line coding approach in swirl. Some of the lectures that are covered in the swirl course, however, also require several lines of code. Here, we broke down the required multi-code into different steps, each containing just one line of code. For better readibility make the console pretty wide so the text doesn’t get too squeezed.

The course can be downloaded here: Data_analysis_with_R.swc

Or from the R-Lab 2.0 project website in which this course was developed. Here, you can find many other interesting swirl courses on different R topics that are in German.

What is swirl?

swirl is an R package that teaches you R programming and data science interactively right in the R console. It is designed so that anyone can create interactive content and share it with others. Once the package is loaded it allows you to start any swirl course you have installed and you will be guided through the individual lessons and exercises step by step.

Installation (only first time)

The package can be installed either directly from CRAN


or you can get the most recent development version from the GitHub repository using the devtools package:

install.packages("devtools")  # if you don't have the package yet
devtools::install_github("swirldev/swirl", ref = "dev")

Start swirl

Every time you want to run swirl you need to load the library and then activate it with the swirl() function:


At this step you will be welcomed and asked for a name (happens every time) that swirl will later use in the exercises. In a next step swirl will prompt you to choose a course. As the package does not come with any course pre-installed, you need to install one now.

Installing courses

You can install one of the recommended courses or choose one from the course repository, the Swirl Course Network or any other one you can find in the internet.

To get an overview of functions that will help you install swirl courses type


You can install a course from the official course repository or a local .swc file using the install_course() function.

# For instance, install the latest version of Team swirl's R Programming course:
install_course(course_name ="R Programming")

Installing the swirl course ‘Data analysis with R’

Downloaded the .swc file “Data_analysis_with_R.swc” (from here and move it a folder of your choice. Install the course from within swirl (i.e., after you loaded and activated swirl) using not the course_name argument as in the previous example but the swc_path argument

install_course(swc_path = "/your_file_path/Data_analysis_with_R.swc")

You should see in the console now “| Course installed successfully!”

To come back to your course overview from where you can select this course, type again


You will be given various information and instructions on how swirl works before you get to the actual course selection menu. Below you will find the summary of swirl functions you can use during the course.

Once you selected the course you get to the lesson overview from where you can choose the lesson you want to run.

Change settings when installing course in RStudio Server

With the introduction of version 2.4.0, swirl includes an interface for options() called swirl_options() which allows you to change where courses are installed on your computer, where swirl user data is stored on your computer, and whether or not swirl should log your progress during lessons.

If you run into an error message in RStudio Server when installing the course (e.g. you are told that the program cannot open the connection and also not find one of the course files in the root folders) a solution can be to set the swirl course directory to the folder where the .swc file is located:

swirl_options(swirl_courses_dir = "/the_path_to_your_folder_containing_the_file")
# and now
install_course(swc_path = "Data_analysis_with_R.swc") # so just the course name, no path

Operating manual

In general,

  • when you see ‘…’, that means you should press Enter.
  • when you see ‘ANSWER:’, the R prompt (>), or when you are asked to select from a list, that means it’s your turn to enter a response, then press Enter to continue.
  • to exit swirl and return to the R prompt (>) at any time press Esc. If you are already at the prompt, type bye() to exit and save your progress.

When you are at the R prompt (>):

  • Typing skip() allows you to skip the current question.
  • Typing play() lets you experiment with R on your own; swirl will ignore what you do…
  • UNTIL you type nxt() which will regain swirl’s attention.
  • Typing bye() causes swirl to exit. Your progress will be saved.
  • Typing main() returns you to swirl’s main menu.
  • Typing info() displays these options again.