3.4 Structure Check (G)
Purpose: Checks whether the student’s variable has the correct data structure (e.g., list, tibble). In most cases, this will be a tibble.
Motivation: Using the wrong data structure may cause the autograder to reject an otherwise correct-looking answer. It can also break Checks that expect a certain data structure, like the Calculation Check.
#Structure Check Example
#For a tibble...
else if(!is_tibble(variable_name)){
test.results[2, 4] <- "Make sure `variable_name` is a tibble. (Any additional feedback as needed.)"
}
#For a list...
#`janitor::tabyl()` and other `janitor` related functions produce a list, not a tibble
#In this case, the Structure Check should check for a list, like below
else if(!is_list(variable_name)){
test.results[2, 4] <- "Make sure `variable_name` is a list. (Any additional feedback as needed.)"
}
Technicals
Always include the Structure Check.
A common mistake students make is using read.csv()
instead of read_csv()
when loading datasets into R. The problem is that the former returns a data frame, while the latter returns a tibble (a special, modern type of data frame).
There are slight differences (Wickham and Grolemund 2016) between how general data frames and tibbles behave in R. For example, tibbles do not change the type of the inputs (e.g., they never convert strings to factors) and they allow for non-syntactic names (e.g., names with spaces). These small differences may cause the autograder to reject the student’s answer or inconvenience the student when solving the assignment.
For Public Questions that involve janitor::tabyl()
and other janitor
related functions (e.g., adorn_pct_formatting
, adorn_totals
), the student’s answer will be a list, not a tibble. In this case, the Structure Check should check for a list. For three-way tabyl
lists, see private_tabyl_grader()
.
Recommendation: For questions that involve loading data into R, tack on a reminder in test.results[#, 4]
for the student to use read_csv()
instead of read.csv()
.