knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The homework
package let's R teachers automatically check homeworks that they are giving to their students. A recommended workflow is to have a master directory for all homework files, and then a sub-directory for each homework assignment (such as "HW01", "HW02", etc.). The master directory will have a check_hw_master.R
master file to include the code to check homework everyweek. A subfolder of homework (say, HW01, HW02, etc.), must have a folder with the submissions of the students (called "submissions"), an R file with the correct solutions (it should be called solutions.R or hw01_solutions.R). The submissions folder can include one zip file with all assignments, or just all the assignments (each student's assignment is an R file). An answer for each homework question should be a function (for example "write a function that calculates the sum of a vector"). The solution file should include an object called tests_to_run
at the end of it. This object is a nested list, each element of the list is a name of a function that the hw has asked for, and in it is either a list of possible inputs to check against the function, OR, a list of lists, each sublist will check some other input (see later for an example). After running the check_hw
on the subdirectory "HW01", the function will create a "mistakes" folder with an .R file for each function in the hw, and in the files will be a list of the mistakes that were found for each question/student. There is also a "grades" folder, with a csv including the grades of students (based on the filenames the students submit). The standard of the filenames of hw assignment is assingment_number_student_id.R (e.g.: 01_123456.R). In the grades folder there is the grades file we need for giving students the grade at the end of the course, plus a file to send the students (this one will include only the first 5 characters of the student's id, so that people won't know who got which grade).
An example of a folder structure before running check_hw:
hw -check_hw_master.R -hw01 --submissions ---students_homework.zip (maybe from moodle) --hw01_solutions.R (includes the corrects functions and the inputs to check) --hw.txt/hw.pdf/hw.docx/etc. (ignored) -hw02 --... -hw03 --...
Folder structure AFTER running check_hw:
hw -check_hw_master.R -hw01 --submissions ---students_homework.zip (maybe from moodle) ---01_123456.R ---01_456987.R ---01_879456.R --hw01_solutions.R (includes the corrects functions and the inputs to check) --mistakes ---mistakes_in_foo.R ---mistakes_in_bar.R --grades ---grades.csv ---grades_for_students.csv --hw.txt/hw.pdf/hw.docx/etc. (ignored) -hw02 --... -hw03 --...
You can install homework from github with:
if(!requireNamespace("remotes", quietly=TRUE)) install.packages("remotes") remotes::install_github("talgalili/homework")
The package comes with a simple example. The following code shows where the example is, and how to run a homework check on it.
Some of the homework file have intentional problems in them to deomnstrate how the function is able to deal with them:
library(homework) # it is best to just create an RStudio project for the homework checking of a course... demo_base_dir <- file.path(system.file(package = "homework"), "extdata") demo_base_dir check_hw("HW01", demo_base_dir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.