Using RStudio with Github Classroom

Posts

In March, 12th, Github has launched the Github Classroom platform.

TL; DR, you can continue. For the long story, click here.

Classroom

For those that want to know more about the capabilities of Github Classroom, I recommend you start here.

Using RStudio

Why do we need this tutorial? Well, Github Classroom already allows an auto-integration with Microsoft MakeCode and Repl.it, but we, as R developers, like RStudio, right? So how to solve this?

The current solution uses mybinder.org as the cloud service that will create our RStudio session. If someone finds out how to use RStudio Cloud automatically, please, send me a message. I’m looking forward to using that.

Step 1 - Create your environment

First, you need to create a repository that will contain the RStudio session settings. That is the best way to do it because if you do not separate the assignment code from the IDE code, every student will have to build its own docker every time they push something new to their assignment. This takes time!

Here I published a template repository where you can derive your configurations:

RStudio MyBinder Environment

Changes you need to make

  • In file .rstudio/projects/settings/last-project-path, you need to change the values there to your own. Leave the /home/jovyan/ there.

Changes you may want to make

  • In file .binder/install.R, you specify the packages that will be installed by default in the environment.

Step 2 - Create the assignment repository

There are some requirements to make this work:

  • The repository must have a .RProj file (e.g., Assignment.Rproj). And this name must be the same you set in Step 1 (in last-project-path). For now, this is a requirement.

  • You must have a README.md with the following link (adapted from the generated URL from nbgitpuller link generator):

<a href="https://mybinder.org/v2/gh/YOUR_USERNAME/YOUR_FORK/main?urlpath=git-pull%3Frepo%3Dhttps%253A%252F%252Fgithub.com%252F${REPOSITORY_ACCOUNT}%252F${REPOSITORY_SLUG}%26targetPath%3DYOUR_CLASSROOM%26urlpath%3Drstudio%252F%26branch%3Dmain">
  <img src="https://mybinder.org/badge_logo.svg" alt="Launch Binder"/>
</a>
  • Pay attention to the strings you must set: YOUR_USERNAME, YOUR_FORK, YOUR_CLASSROOM.

    Also pay attention that recently, Github is changing the default repository from master to main.

    The variables ${REPOSITORY_SLUG} are variables that will be automatically replaced by a Github action. Explained in the long story post.

    If you generate the README.md from an Rmd file, it is really recommended that you use the plain HTML above since knitr or something else seems to recode the URL, and I could not find a way to disable that.

  • Create a workflow at .github/workflows/configure_readme.yml with the following Github action: replace_envs. And, to avoid this action runs in your template, but in student’s fork, add this line before steps:

if: contains(github.event.head_commit.message, 'Classroom')

Step 3 - The autograding

Github Classroom has an option to create an automatic grading, so the students can push answers for solving the assessment, and the system will automatically verify if it is right.

That is not fancy stuff;you have to define what is right or wrong and how much.

I’ve tried to leave my files in the template repository, but Github Classroom will currently overwrite them when the student accepts the task.

So, how I’m doing currently:

  • Create a test.R file, and use your skills to assess the student’s answer. My lazy approach makes the student save a file called output.rda containing the variable answer, and my script loads the output.rda file and compares the SHA1 of the answer with the right answer. Use quit(status = 0) and quit(status = 1) to tell the system that the answer is ok or not.

  • Create a test.sh file that calls the test.R file. This script can handle several R scripts separately if you want to test for several answers and make partial grading, for example. Just use a bash script like:

echo "Running tests..."

if Rscript --vanilla .assets/scripts/test.R ; then
 echo "Pass: Program exited zero"
else
 echo "Fail: Program did not exit zero"
 exit 1
fi

echo "All tests passed."

exit 0
  • Finally, when you create the auto-grading in your assignment, choose the options:

    • Repository: Public. That is a limitation (for now) since nbgitpuller doesn’t have access to private repositories. That may be a problem for countries that require that student assignments must be private.

    • Online IDE: Don't use an online IDE.

    • Add test: Run Command.

      In this option, set as setup:

      sudo apt-get update; sudo apt-get remove -y r-base r-base-core; sudo apt-get install -y r-base r-base-core r-cran-digest (this removes and installs again the R in the test environment, because if you use the one it is there, some important packages as r-cran-ggplot2 will fail to install. Additionally, I install the r-cran-digest package that has the SHA1 algorithm.)

      and as run:

      bash .assets/scripts/test.sh

I hope this post can save some academic lives, or at least save some time, and maybe get some Github’s or RStudio’s attention to this matter.

Any comment is welcome.