3.6 Row & Column Check (G)

Purpose: Checks whether the student’s tibble has the same number of rows and columns as the answer key.

Motivation: Many questions involve the deletion or addition of rows and/or columns in a tibble. This Check alerts students, rather broadly, to a discrepancy in their number of rows and columns. Row and column mismatches can cause Checks, like the Correct Check, to error out.

#Row & Column Check Example

#Row Check
else if(nrow(variable_name) != nrow(variable_name_test)){ 
  test.results[2, 4] <- "`variable_name` has the incorrect number of rows. (Any additional feedback as needed.)"
}

#Column Check 
else if(ncol(variable_name) != ncol(variable_name_test)){ 
  test.results[2, 4] <- "`variable_name` has the incorrect number of columns. (Any additional feedback as needed.)"
}

Technicals

Always include the Row & Column Check.

Please note that the Column Check is redundant if it follows the Column Name Check. That is, if the student’s answer passes the Column Name Check, it inevitably passes the Column Check. However, there are cases where the Column Check should precede the Column Name Check (e.g., if the tibble is very large, it is reasonable to first ensure that the number of columns is correct before checking for column names to potentially avoid a long Column Name Check message).

You may notice that 2024 ECON 145 autograders have this redundant Column Check. This is not really necessary, but is done to completely ensure that the Correct Check works smoothly.

The Row & Column Check can easily be adapted for vectors by swapping nrow() and ncol() for length().