6.3 private_tabyl_grader()
Description
Grades Private Questions involving three-way tabyl
objects from the janitor
package (Firke 2024a).
This function implements many of the General Checks discussed earlier.
Arguments
Element | Description | Default |
---|---|---|
var_name | character, the expected name of var | - |
var | expected tabyl object, the student’s tabyl | - |
var_test | other tabyl object, the answer key’s tabyl to be compared with var | - |
status | character, the question’s displayed part, number, and type (Private/Public) | paste0(“Question”, quest_num, ” (Private)“) |
prev_check | logical indicating if the Prerequisite Check should be triggered; requires quest_prev value and can optionally be combined with quest_prev_status | TRUE |
quest_num | numeric, the question’s number | 0 |
quest_pt | numeric, the question’s maximum score | 0 |
quest_prev | numeric, the prerequisite question’s number | 1 |
quest_prev_status | character, the prerequisite question’s part and number | NULL |
Value
The test.results[#, ]
vector, containing the question’s status
, amount of points awarded, total point value, and feedback message.
See What is test.results? for more details.
Details
Designed for grading three-way tabyl objects only (i.e., objects with a tabyl
class attribute).
Use private_grader()
for two-way tabyl objects.
As with the other functions, var
may not necessarily exist or be a tabyl object.
- This is not a problem because
private_tabyl_grader()
first tests for atabyl
class attribute and then performs the Name Check.
Likewise, quest_prev_status
is an optional argument when using prev_check
and quest_prev
but helps clarify an unclear prerequisite question’s location in the feedback message.
What is a three-way tabyl?
A three-way tabyl is a multi-table created from three variables that is produced by the janitor::tabyl()
function.
A three-way tabyl will typically create two “sub-tables.”
Consider the following example from the tabyl
documentation (Firke 2024b):
t3 <- starwars |>
filter(species == "Human") |>
tabyl(eye_color, skin_color, gender)
#The result is a tabyl of eye color x skin color, split into a list by gender
## $feminine
## eye_color dark fair light none pale tan white
## blue 0 2 1 0 0 0 0
## blue-gray 0 0 0 0 0 0 0
## brown 0 1 3 0 0 0 0
## dark 0 0 0 0 0 0 0
## hazel 0 0 1 0 0 0 0
## unknown 0 0 0 1 0 0 0
## yellow 0 0 0 0 0 0 0
##
## $masculine
## eye_color dark fair light none pale tan white
## blue 0 7 2 0 0 0 0
## blue-gray 0 1 0 0 0 0 0
## brown 3 4 3 0 0 2 0
## dark 1 0 0 0 0 0 0
## hazel 0 1 0 0 0 0 0
## unknown 0 0 0 0 0 0 0
## yellow 0 0 0 0 1 0 1
Example
Consider the following modified question from the Final.
Part 3: Creating Tables and Figures
- (Private Question) Using
schoolData
, create a table that shows the percentage of schools that provide free lunch to all students, and how for each year in eachlocale
category (City, Suburb, Town, and Rural). Make sure you remove any rows with missingnational_school_lunch_program
orlocale
values before creating your table. Save this table asnslp_locale_table
.
The answer should look something like:
#Note: This has been slightly modified from the actual solution
nslp_locale_table <- schoolData |>
filter(!is.na(locale) & !is.na(national_school_lunch_program)) |>
janitor::tabyl(year, national_school_lunch_program, locale) |>
janitor::adorn_percentages() |>
janitor::adorn_pct_formatting()
Assume this question is worth 5 points, is the sixteenth question of the assignment, and that schoolData
was created in Part 1 Question 1b (the second question).
Then, the autograder code for this question should look like:
#Comparing the student's three-way tabyl `nslp_locale_table` with the answer key's `nslp_locale_table_test`
test.results[16, ] <- private_tabyl_grader("nslp_locale_table", nslp_locale_table, nslp_locale_table_test,
status = "Part 3 Question 1 (Private)", prev_check = TRUE,
quest_prev = 2, quest_prev_status = "Part 1 Question 1b",
quest_num = 16, quest_pt = 5)