R Studio - Exclusion List for R Code

Nick Updated by Nick

R Studio - Exclusion List for Autograders

This article covers adding an "exclusions list" (collection of certain R code meant to manipulate the student's saved code). As of the date of this article, R Studio doesn't have the ability to automatically grade the student's code, so we internally grade the student's saved worked inside of Codio with our own autograding code.

  1. Before saving the student's code to a PDF, CSV, etc., if we want to omit certain snippets of code from the student's solution, we can create a copy of the student's code in our autograder.sh file by using the cp command. For example:
# autograder.sh

cp oldFile.R newFile.R # make a copy of the student's code

  1. Then, we want to create a bash file that will include the list of all snippets of R code that we want to omit from the student's solution code. For this example, we'll call the file sanitize.sh. We will then want to call that file from our autograder file after the student's solution code file has been copied. For example:
# autograder.sh

cp oldFile.R newFile.R # make a copy of the student's code
sh sanitize.sh # run the sanitize file to remove snippets of unwanted R code

  1. Next, we need to put our list of R code that we want to remove from the student's solution code inside of the sanitize.r file. We can use the sed command to remove which parts we want omitted. For example, if we want to remove any X or Y-axis labels (xlab and ylab) or the the title (ggtitle) of the plot, we can use the following commands inside the sanitize.sh file:
# sanitize.sh

sed -i 's/xlab.*+//g' newFile.R # Remove any X-axis labels
sed -i 's/ylab.*+//g' newFile.R # Remove any Y-axis labels
sed -i 's/ggtitle.*+//g' newFile.R # Remove any table names

Note: At the end of each sed command, we need to add which file we want to have the command be run on. In the example above, we are omitting code from the newFile.R file.

If you want to remove white space from the file, you can use the following command:

sed -i '/^$/d;s/[[:blank:]]//g' newFile.R

For more information on using the sed command to remove text from a file, please see here.

  1. Finally, back in our autograder file and after the newFile.R file has all of the necessary code snippets that we want removed, we can run the new version of the student's code . The code snippet in autograder.sh will now look something like the following:
# autograder.sh

cp oldFile.R newFile.R # make a copy of the student's code
sh sanitize.sh # run the sanitize file to remove snippets of unwanted R code
R CMD BATCH --no-timing newFile.R # run the new version of the student's code

From there, your R file can save the student's work into a PDF, CSV etc. so we can evaluate and test.

How did we do?

Setting Up the Class Fork

Mocha/Selenium Autograding

Contact