Skip to content

Creating a New Course

Sean Kross edited this page Jun 3, 2016 · 5 revisions

ATTENTION!

This documentation is deprecated. For the latest version of the swirlify documentation please visit: http://swirlstats.com/swirlify

First make sure that your current working directory is the directory where you want your swirl course to be saved. I have a folder in my ~/Developer/ directory where I like to work on swirl courses called my_swirl_courses/ so I'm going to set that as my current working directory now:

setwd("~/Developer/my_swirl_courses/")

Now I'm going to create a new course using the new_lesson() function. Whenever you create a new course you will also automatically create a new lesson inside of that course.

# Don't forget to load swirlfiy!
library(swirlify)

# The name of the lesson is 'How to use pnorm'
# The name of the course is 'Normal Distribution Functions in R'
new_lesson("How to use pnorm", "Normal Distribution Functions in R")

Executing the new_lesson() function will open up a lesson.yaml file in your text editor. This lesson.yaml file will contain most of the contents of your lesson! Before we continue, let's take a look at the file/folder structure that new_lesson() created:

~/Developer/my_swirl_courses/
└─ Normal_Distribution_Functions_in_R
   └─ How_to_use_pnorm
      ├─ lesson.yaml
      ├─ initLesson.R
      ├─ dependson.txt
      └─ customTests.R
  • lesson.yaml is where you will write all of the questions for this lesson.
  • initLesson.R is an R script that is run immediately before the lesson starts. You can use initLesson.R to load datasets or to set up other environmental variables.
  • dependson.txt is a list of R packages that your course requires. When the lesson begins, swirl will attempt to load every package listed in dependson.txt and if a package is not installed the user will be asked if they want to install the package. If the user indicates that they do want to install the package then the package will be installed from CRAN. dependson.txt should list only one package name per line.
  • The purpose of customTests.R is thoroughly discussed in Writing Custom Tests.

Time to add some questions to your new lesson! Find out how in Adding Questions to a Lesson. You might be curious about how to resume working on a swirl course you've already started, in that case you should read Creating a New Lesson in an Existing Course and Resuming Work on a Lesson in an Existing Course.