Automatically grade a table resulting from student code using
gradethis::grade_this()
and tbl_grade()
to compare the
student's result with the author's solution.
Usage
grade_this_table(
correct = NULL,
pre_check = NULL,
post_check = NULL,
pass_if_equal = TRUE,
...,
max_diffs = 3,
cols = NULL,
check_class = TRUE,
ignore_class = NULL,
check_names = TRUE,
check_column_order = FALSE,
check_dimensions = TRUE,
check_groups = TRUE,
check_columns = TRUE,
check_column_class = check_columns,
check_column_values = check_columns,
hint = getOption("gradethis.fail.hint", FALSE),
encourage = getOption("gradethis.fail.encourage", FALSE),
pass.praise = NULL
)
Arguments
- correct
[character(1)]
The message shown to the student when their.result
matches the exercise.solution
, ifpass_if_equal
isTRUE
.- pre_check, post_check
[expression]
Code to run before or after the table or vector grading is performed. The pre check runs before callinggradethis::pass_if_equal()
so that you can modify or adjust the student's.result
or the.solution
if there are parts of either that need to be ignored. These arguments can also be used in conjunction with thepass_if_equal
option when the grading requirements are more involved.- pass_if_equal
[logical(1)]
WhenTRUE
(default), the.result
is compared to the.solution
withgradethis::pass_if_equal()
after the pre check and before calling the tblcheck grading function. WhenFALSE
, you will need to include your own call togradethis::pass()
in eitherpre_check
orpost_check
for the student to be able to receive a passing grade.- ...
Additional arguments passed to
graded()
or additional data to be included in the feedback object.- max_diffs
[numeric(1)]
The maximum number of mismatched values to display in an informative failure message. Passed totbl_check_names()
to determine the number of mismatched column names to display and then_values
argument oftbl_check_column()
to determine the number of mismatched column values to display. Defaults to 3.- cols
[
tidy-select
]
A selection of columns to compare betweenobject
andexpected
. Differences in other columns will be ignored. IfNULL
, the default, all columns will be checked.- check_class
[logical(1)]
Whether to check thatobject
andexpected
have the same classes withtbl_check_class()
.- ignore_class
[character()]
A vector of classes to ignore when finding differences betweenobject
andexpected
.If an element is named, differences will only be ignored between the pair of the element and its name. For example,
ignore_class = c("integer" = "numeric")
will ignore class differences only ifobject
has class integer andexpected
has class numeric, or vice versa.If all the classes of
expected
are included inignore_class
, aclass
problem will never be returned.- check_names
[logical(1)]
Whether to check thatobject
andexpected
have the same column names withtbl_check_names()
.- check_column_order
[logical(1)]
Whether to check that the columns ofobject
are in the same order asexpected
withtbl_check_names()
. Defaults toFALSE
.- check_dimensions
[logical(1)]
Whether to check thatobject
andexpected
have the same number of rows and columns withtbl_check_dimensions()
.- check_groups
[logical(1)]
Whether to check thatobject
andexpected
have the same groups withdplyr::group_vars()
.- check_columns
[logical(1)]
Whether to check that all columns have the same contents withtbl_check_column()
.- check_column_class
[logical(1)]
Whether to check that each columns has the same class inobject
andexpected
.- check_column_values
[logical(1)]
Whether to check that each column has the same values inobject
andexpected
.- hint
Include a code feedback hint with the failing message? This argument only applies to
fail()
andfail_if_equal()
and the message is added using the default options ofgive_code_feedback()
andmaybe_code_feedback()
. The default value ofhint
can be set usinggradethis_setup()
or thegradethis.fail.hint
option.- encourage
Include a random encouraging phrase with
random_encouragement()
? The default value ofencourage
can be set usinggradethis_setup()
or thegradethis.fail.encourage
option.- pass.praise
Logical
TRUE
orFALSE
to determine whether a praising phrase should be automatically prepended to anypass()
orpass_if_equal()
messages. Sets thegradethis.pass.praise
option.
Value
The returned feedback is equivalent to gradethis grading code
using grade_this()
with the following
components:
First the
pre_check
code, if any, is evaluated. If this code callspass()
,fail()
, or their equivalents, that feedback is provided immediately.If
pass_if_equal
isTRUE
, thenpass_if_equal()
is called to compare the.result
to the.solution
. The message incorrect
is used for the feedback.The appropriate tblcheck grading function is called, returning any feedback:
grade_this_table()
returns the results fromtbl_grade()
grade_this_vector()
returns the results fromvec_grade()
The
post_check
code, if any, is evaluated and any feedback from a call topass()
,fail()
, or their equivalents is returned.Finally, if no other feedback is returned, the feedback from
gradethis::fail()
is provided to the student, using the optionsfail.message
,fail.hint
andfail.encourage
.
See also
Other graders:
grade_this_vector()
Examples
ex <- gradethis::mock_this_exercise(
.solution_code = tibble::tibble(x = 1:3, y = letters[x]),
.user_code = tibble::tibble(x = 1:3, y = c("A", "b", "c"))
)
## Grading Tables ----
grade_this_table()(ex)
#> #> grade_this_table()(ex)
#> Error in get(".__tblcheck_grader_args"): object '.__tblcheck_grader_args' not found
#> <tblcheck_graded: [Neutral]
#> A problem occurred with the grading code for this exercise.
#> >
# Roughly equivalent to...
gradethis::grade_this({
gradethis::pass_if_equal()
tbl_grade()
gradethis::fail()
})(ex)
#> <gradethis_graded: [Incorrect]
#> The first 3 values of your `y` column should be `a`, `b`, and
#> `c`, not `A`, `b`, and `c`.
#> >