3.5 Column Name Check (G)
Purpose: Dynamically checks whether the column names in the student’s tibble (A) match those in the answer key (B). We break this test into two parts:
Test whether \(B \not\subset A\), that is, if the student’s tibble is missing any column names from the answer key.
Test whether \(A \not\subset B\), that is, if the student’s tibble has any additional column names not in the answer key.
Motivation: Many questions involve the deletion or addition of columns in a tibble. Students often misname, omit, or forget to remove such columns. This Check helps catch these issues early, reducing the time students spends sifting through their code for a simple mistake (e.g., a typo).
#Column Name Check Example
#First Test (B not in A)
else if(!all(colnames(variable_name_test) %in% colnames(variable_name))){
test.results[2, 4] <- paste0(c("The following column(s) should be in `variable_name`, but they were not found in your answer: ",
paste0(colnames(variable_name_test)[!(colnames(variable_name_test) %in% colnames(variable_name))], collapse = ", "), ". (Any additional feedback as needed.)"), collapse = "")
}
#Second Test (A not in B)
else if(!all(colnames(variable_name) %in% colnames(variable_name_test))){
test.results[2, 4] <- paste0(c("The following column(s) should not be in `variable_name`, but they were found in your answer: ",
paste0(colnames(variable_name)[!(colnames(variable_name) %in% colnames(variable_name_test))],
collapse = ", "), ". (Any additional feedback as needed.)"), collapse = "")
}
Technicals
Always include the Column Name Check.
This Check is essential for subsequent Checks that rely on the student’s answer having correctly named columns, like the Correct Check.
While the Column Name Check is designed for tibbles, it can easily be adapted for named lists by swapping colnames()
for names()
. Please note that lists should first be checked if they are named through a NULL
Check like is.null(names(variable_name))
.