| Title: | Grade Tables in Learning Exercises |
|---|---|
| Description: | 'tblcheck' extends 'gradethis' with functions that inspect data frame or tibble objects to make it easier for teachers to check that student tables meet expectations. |
| Authors: | Alexander Rossell Hayes [aut, cre] (ORCID: <https://orcid.org/0000-0001-9412-0457>), Garrick Aden-Buie [aut] (ORCID: <https://orcid.org/0000-0002-7111-0077>), Sara Altman [ctb] (ORCID: <https://orcid.org/0000-0002-2529-5680>), RStudio, PBC [cph, fnd] |
| Maintainer: | Alexander Rossell Hayes <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.1 |
| Built: | 2026-06-05 06:54:39 UTC |
| Source: | https://github.com/rstudio/tblcheck |
Generate a human-readable description of an object's class
friendly_class(object) ## S4 method for signature 'ANY' friendly_class(object) ## S4 method for signature 'character' friendly_class(object) ## S4 method for signature 'numeric' friendly_class(object) ## S4 method for signature 'integer' friendly_class(object) ## S4 method for signature 'logical' friendly_class(object) ## S4 method for signature 'complex' friendly_class(object) ## S4 method for signature 'raw' friendly_class(object) ## S4 method for signature 'factor' friendly_class(object) ## S4 method for signature 'Date' friendly_class(object) ## S4 method for signature 'POSIXt' friendly_class(object) ## S4 method for signature 'Period' friendly_class(object) ## S4 method for signature 'data.frame' friendly_class(object) ## S4 method for signature 'tbl_df' friendly_class(object) ## S4 method for signature 'grouped_df' friendly_class(object) ## S4 method for signature 'rowwise_df' friendly_class(object) ## S4 method for signature 'list' friendly_class(object) ## S4 method for signature 'matrix' friendly_class(object) ## S4 method for signature 'array' friendly_class(object)friendly_class(object) ## S4 method for signature 'ANY' friendly_class(object) ## S4 method for signature 'character' friendly_class(object) ## S4 method for signature 'numeric' friendly_class(object) ## S4 method for signature 'integer' friendly_class(object) ## S4 method for signature 'logical' friendly_class(object) ## S4 method for signature 'complex' friendly_class(object) ## S4 method for signature 'raw' friendly_class(object) ## S4 method for signature 'factor' friendly_class(object) ## S4 method for signature 'Date' friendly_class(object) ## S4 method for signature 'POSIXt' friendly_class(object) ## S4 method for signature 'Period' friendly_class(object) ## S4 method for signature 'data.frame' friendly_class(object) ## S4 method for signature 'tbl_df' friendly_class(object) ## S4 method for signature 'grouped_df' friendly_class(object) ## S4 method for signature 'rowwise_df' friendly_class(object) ## S4 method for signature 'list' friendly_class(object) ## S4 method for signature 'matrix' friendly_class(object) ## S4 method for signature 'array' friendly_class(object)
object |
An object whose class will be described |
A character string of length 1,
based on the class and length of object.
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.
grade_this_table( correct = NULL, pre_check = NULL, post_check = NULL, pass_if_equal = FALSE, ..., 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_levels = check_columns, check_column_values = check_columns, tolerance = sqrt(.Machine$double.eps), check_row_order = check_columns, hint = getOption("gradethis.fail.hint", FALSE), encourage = getOption("gradethis.fail.encourage", FALSE), pass.praise = NULL )grade_this_table( correct = NULL, pre_check = NULL, post_check = NULL, pass_if_equal = FALSE, ..., 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_levels = check_columns, check_column_values = check_columns, tolerance = sqrt(.Machine$double.eps), check_row_order = check_columns, hint = getOption("gradethis.fail.hint", FALSE), encourage = getOption("gradethis.fail.encourage", FALSE), pass.praise = NULL )
correct |
|
pre_check, post_check
|
|
pass_if_equal |
|
... |
Additional arguments passed to |
max_diffs |
|
cols |
[ |
check_class |
|
ignore_class |
If an element is named, differences will only be ignored between the pair
of the element and its name.
For example, If all the classes of |
check_names |
|
check_column_order |
|
check_dimensions |
|
check_groups |
|
check_columns |
|
check_column_class |
|
check_column_levels |
|
check_column_values |
|
tolerance |
|
check_row_order |
|
hint |
Include a code feedback hint with the failing message? This
argument only applies to |
encourage |
Include a random encouraging phrase with
|
pass.praise |
Logical |
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 calls
pass(), fail(), or their
equivalents, that feedback is provided immediately.
If pass_if_equal is TRUE, then
pass_if_equal() is called to compare the
.result to the
.solution. The message in correct
is used for the feedback.
The appropriate tblcheck grading function is called, returning any feedback:
grade_this_table() returns the results from tbl_grade()
grade_this_vector() returns the results from vec_grade()
The post_check code, if any, is evaluated and any feedback from a call
to pass(), 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 options
fail.message, fail.hint and fail.encourage.
Other graders:
grade_this_vector()
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) # Roughly equivalent to... gradethis::grade_this({ gradethis::pass_if_equal() tbl_grade() gradethis::fail() })(ex)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) # Roughly equivalent to... gradethis::grade_this({ gradethis::pass_if_equal() tbl_grade() gradethis::fail() })(ex)
Automatically grade a vector resulting from student code using
gradethis::grade_this() and vec_grade() to compare the
student's result with the author's solution.
grade_this_vector( correct = NULL, pre_check = NULL, post_check = NULL, pass_if_equal = TRUE, ..., max_diffs = 3, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = TRUE, hint = getOption("gradethis.fail.hint", FALSE), encourage = getOption("gradethis.fail.encourage", FALSE), pass.praise = NULL )grade_this_vector( correct = NULL, pre_check = NULL, post_check = NULL, pass_if_equal = TRUE, ..., max_diffs = 3, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = TRUE, hint = getOption("gradethis.fail.hint", FALSE), encourage = getOption("gradethis.fail.encourage", FALSE), pass.praise = NULL )
correct |
|
pre_check, post_check
|
|
pass_if_equal |
|
... |
Additional arguments passed to |
max_diffs |
|
check_class |
|
ignore_class |
If an element is named, differences will only be ignored between the pair
of the element and its name.
For example, If all the classes of |
check_length |
|
check_levels |
|
check_values |
|
tolerance |
|
check_names |
|
hint |
Include a code feedback hint with the failing message? This
argument only applies to |
encourage |
Include a random encouraging phrase with
|
pass.praise |
Logical |
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 calls
pass(), fail(), or their
equivalents, that feedback is provided immediately.
If pass_if_equal is TRUE, then
pass_if_equal() is called to compare the
.result to the
.solution. The message in correct
is used for the feedback.
The appropriate tblcheck grading function is called, returning any feedback:
grade_this_table() returns the results from tbl_grade()
grade_this_vector() returns the results from vec_grade()
The post_check code, if any, is evaluated and any feedback from a call
to pass(), 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 options
fail.message, fail.hint and fail.encourage.
Other graders:
grade_this_table()
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 Vectors ---- # Here we use `pre_check` to modify `.result` and grade_this_vector( pre_check = { .result <- .result$y .solution <- .solution$y } )(ex) # Roughly equivalent to... gradethis::grade_this({ .result <- .result$y .solution <- .solution$y gradethis::pass_if_equal() vec_grade() gradethis::fail() })(ex)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 Vectors ---- # Here we use `pre_check` to modify `.result` and grade_this_vector( pre_check = { .result <- .result$y .solution <- .solution$y } )(ex) # Roughly equivalent to... gradethis::grade_this({ .result <- .result$y .solution <- .solution$y gradethis::pass_if_equal() vec_grade() gradethis::fail() })(ex)
Generate a hint for how to convert one object type to another
hinted_class_message(object, expected) ## S4 method for signature 'ANY,ANY' hinted_class_message(object, expected) ## S4 method for signature 'rowwise_df,grouped_df' hinted_class_message(object, expected) ## S4 method for signature 'data.frame,grouped_df' hinted_class_message(object, expected) ## S4 method for signature 'grouped_df,data.frame' hinted_class_message(object, expected) ## S4 method for signature 'data.frame,rowwise_df' hinted_class_message(object, expected) ## S4 method for signature 'rowwise_df,data.frame' hinted_class_message(object, expected)hinted_class_message(object, expected) ## S4 method for signature 'ANY,ANY' hinted_class_message(object, expected) ## S4 method for signature 'rowwise_df,grouped_df' hinted_class_message(object, expected) ## S4 method for signature 'data.frame,grouped_df' hinted_class_message(object, expected) ## S4 method for signature 'grouped_df,data.frame' hinted_class_message(object, expected) ## S4 method for signature 'data.frame,rowwise_df' hinted_class_message(object, expected) ## S4 method for signature 'rowwise_df,data.frame' hinted_class_message(object, expected)
object |
An object to be compared to |
expected |
An object of the expected class |
A character string of length 1
Useful for constructing a small list to communicate the problem that was discovered during checking.
problem( type, expected, actual, ..., .class = c(paste0(type, "_problem"), "tblcheck_problem") )problem( type, expected, actual, ..., .class = c(paste0(type, "_problem"), "tblcheck_problem") )
type |
A character string, e.g. |
expected, actual
|
The expected and actual values. These should be
included when the value is a summary, e.g. |
... |
Additional elements to be included in the |
.class |
The class of the problem. Typically, we expect the problem
class to be |
Returns a problem with class <type>_problem and the base classes
tblcheck_problem and gradethis_problem.
Other Problem functions:
problem_grade(),
problem_message(),
problem_type()
problem( type = "class", expected = "character", actual = "numeric", expected_length = 1, actual_length = 2 )problem( type = "class", expected = "character", actual = "numeric", expected_length = 1, actual_length = 2 )
Automatically converts a problem() object into a gradethis grade.
problem_grade() is an S4 generic and tblcheck provides an internal
method for problems with class "tblcheck_problem". In tblcheck, or
for problems with this class, any problems are automatically turned into
failing grades with gradethis::fail() and using the message provided by
problem_message().
problem_grade(problem, max_diffs = 3, env = parent.frame(), ...) ## Default S3 method: problem_grade(problem, max_diffs = 3, env = parent.frame(), ...) ## S3 method for class 'list' problem_grade(problem, max_diffs = 3, env = parent.frame(), ...) ## S3 method for class 'gradethis_problem' problem_grade(problem, max_diffs = 3, env = parent.frame(), ...) ## S3 method for class 'tblcheck_problem' problem_grade(problem, max_diffs = 3, env = parent.frame(), ...)problem_grade(problem, max_diffs = 3, env = parent.frame(), ...) ## Default S3 method: problem_grade(problem, max_diffs = 3, env = parent.frame(), ...) ## S3 method for class 'list' problem_grade(problem, max_diffs = 3, env = parent.frame(), ...) ## S3 method for class 'gradethis_problem' problem_grade(problem, max_diffs = 3, env = parent.frame(), ...) ## S3 method for class 'tblcheck_problem' problem_grade(problem, max_diffs = 3, env = parent.frame(), ...)
problem |
A problem generated by |
max_diffs |
|
env |
The environment used for grading. |
... |
Arguments passed on to
|
A gradethis::fail() message or NULL invisibly.
Other Problem functions:
problem_message(),
problem_type(),
problem()
.result <- 1:10 .solution <- letters[1:10] problem <- vec_check() problem_grade(problem).result <- 1:10 .solution <- letters[1:10] problem <- vec_check() problem_grade(problem)
problem_message() is an S3 generic that powers the conversion of problems
detected by tbl_check(), vec_check(), and their related helper functions
into a human-readable message.
problem_message(problem, ...)problem_message(problem, ...)
problem |
An object with base class |
... |
Additional arguments passed to the underlying methods. |
A length-1 character string with a message describing the problem.
Other Problem functions:
problem_grade(),
problem_type(),
problem()
problem <- problem( type = "class", expected = "character", actual = "numeric", expected_length = 1, actual_length = 2 ) problem_message(problem)problem <- problem( type = "class", expected = "character", actual = "numeric", expected_length = 1, actual_length = 2 ) problem_message(problem)
problem_type() returns a problem's type, or NULL if the input is
not a problem.
is_problem() tests whether an object is a gradethis problem.
is_tblcheck_problem() tests whether an object is a problem created
by tblcheck.
as_problem() converts a list to a tblcheck_problem.
problem_type(x) is_problem(x, type = NULL) is_tblcheck_problem(x, type = NULL) as_problem(x)problem_type(x) is_problem(x, type = NULL) is_tblcheck_problem(x, type = NULL) as_problem(x)
x |
An object |
type |
|
If type is specified, is_problem() and is_tblcheck_problem() test
whether an object is a problem of the specified type.
is_problem() and is_tblcheck_problem() return a logical
of length 1.
problem_type() returns a character of length 1.
as_problem() returns a tblcheck_problem.
Other Problem functions:
problem_grade(),
problem_message(),
problem()
problem_type(vec_check(1, "1")) is_problem(vec_check(1, "1"), "vector_class") is_tblcheck_problem(vec_check(1, "1"), "class")problem_type(vec_check(1, "1")) is_problem(vec_check(1, "1"), "vector_class") is_tblcheck_problem(vec_check(1, "1"), "class")
Checks for differences between object and expected in the following order:
Check table class with tbl_check_class()
Check column names with tbl_check_names()
Check number of rows and columns with tbl_check_dimensions()
Check groups with tbl_check_groups()
Check that each column is the same with tbl_check_column()
If the tables differ
tbl_check() returns a list describing the problem
tbl_grade() returns a failing grade and informative message
with gradethis::fail()
tbl_check( object = .result, expected = .solution, 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_levels = check_columns, check_column_values = check_columns, tolerance = sqrt(.Machine$double.eps), check_row_order = check_columns, env = parent.frame() ) tbl_grade( object = .result, expected = .solution, cols = NULL, max_diffs = 3, 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_levels = check_columns, check_column_values = check_columns, tolerance = sqrt(.Machine$double.eps), check_row_order = check_columns, env = parent.frame(), ... )tbl_check( object = .result, expected = .solution, 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_levels = check_columns, check_column_values = check_columns, tolerance = sqrt(.Machine$double.eps), check_row_order = check_columns, env = parent.frame() ) tbl_grade( object = .result, expected = .solution, cols = NULL, max_diffs = 3, 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_levels = check_columns, check_column_values = check_columns, tolerance = sqrt(.Machine$double.eps), check_row_order = check_columns, env = parent.frame(), ... )
object |
A data frame to be compared to |
expected |
A data frame containing the expected result. |
cols |
[ |
check_class |
|
ignore_class |
If an element is named, differences will only be ignored between the pair
of the element and its name.
For example, If all the classes of |
check_names |
|
check_column_order |
|
check_dimensions |
|
check_groups |
|
check_columns |
|
check_column_class |
|
check_column_levels |
|
check_column_values |
|
tolerance |
|
check_row_order |
|
env |
The environment in which to find |
max_diffs |
|
... |
Arguments passed on to
|
If there are any issues, a list from tbl_check() or a
gradethis::fail() message from tbl_grade().
Otherwise, invisibly returns NULL.
class: The table does not have the expected classes.
not_table: object does not inherit the data.frame class.
names: The table has column names that are not expected,
or is missing names that are expected.
names_order: The table has the same column names as expected,
but in a different order.
ncol: The table doesn't have the expected number of columns.
nrow: The table doesn't have the expected number of rows.
groups: The table has groups that are
not expected, or is missing groups that are expected.
Additional problems may be produced by tbl_check_column().
.result <- data.frame(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 1:10, b = 11:20) tbl_check() tbl_grade() .result <- tibble::tibble(a = 1:10, b = a, c = a, d = a, e = a, f = a) .solution <- tibble::tibble(z = 1:10, y = z, x = z, w = z, v = z, u = z) tbl_check() tbl_grade() tbl_grade(max_diffs = 5) tbl_grade(max_diffs = Inf) .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 1:11, b = 12:22) tbl_check() tbl_grade() .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = letters[1:10], b = letters[11:20]) tbl_check() tbl_grade() .result <- tibble::tibble(a = 1:10, intermediate = 6:15, b = 11:20) .solution <- tibble::tibble(a = 1:10, b = 11:20) tbl_check(cols = any_of(names(.solution))) tbl_grade(cols = any_of(names(.solution))) .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 11:20, b = 1:10) tbl_check() tbl_grade() tbl_grade(max_diffs = 5) tbl_grade(max_diffs = Inf) .result <- tibble::tibble(a = 1:10, b = rep(1:2, 5)) .solution <- dplyr::group_by(tibble::tibble(a = 1:10, b = rep(1:2, 5)), b) tbl_check() tbl_grade() tbl_grade(check_groups = FALSE).result <- data.frame(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 1:10, b = 11:20) tbl_check() tbl_grade() .result <- tibble::tibble(a = 1:10, b = a, c = a, d = a, e = a, f = a) .solution <- tibble::tibble(z = 1:10, y = z, x = z, w = z, v = z, u = z) tbl_check() tbl_grade() tbl_grade(max_diffs = 5) tbl_grade(max_diffs = Inf) .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 1:11, b = 12:22) tbl_check() tbl_grade() .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = letters[1:10], b = letters[11:20]) tbl_check() tbl_grade() .result <- tibble::tibble(a = 1:10, intermediate = 6:15, b = 11:20) .solution <- tibble::tibble(a = 1:10, b = 11:20) tbl_check(cols = any_of(names(.solution))) tbl_grade(cols = any_of(names(.solution))) .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 11:20, b = 1:10) tbl_check() tbl_grade() tbl_grade(max_diffs = 5) tbl_grade(max_diffs = Inf) .result <- tibble::tibble(a = 1:10, b = rep(1:2, 5)) .solution <- dplyr::group_by(tibble::tibble(a = 1:10, b = rep(1:2, 5)), b) tbl_check() tbl_grade() tbl_grade(check_groups = FALSE)
Checks if object and expected have the same class.
If the classes differ
tbl_check_class() and vec_check_class() return a list describing
the problem
tbl_grade_class() and vec_grade_class() return a failing grade and
informative message with gradethis::fail()
tbl_check_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame() ) vec_check_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame() ) tbl_grade_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame(), ... ) vec_grade_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame(), ... )tbl_check_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame() ) vec_check_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame() ) tbl_grade_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame(), ... ) vec_grade_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame(), ... )
object |
An object to be compared to |
expected |
An object containing the expected result. |
ignore_class |
If an element is named, differences will only be ignored between the pair
of the element and its name.
For example, If all the classes of |
env |
The environment in which to find |
... |
Arguments passed on to
|
If there are any issues, a list from tbl_check_class() and
vec_check_class() or a gradethis::fail() message from
tbl_grade_class() and vec_grade_class().
Otherwise, invisibly returns NULL.
class: The object does not have the expected classes
.result <- 1:10 .solution <- as.character(1:10) vec_check_class() vec_grade_class() .result <- data.frame(a = 1:10) .solution <- tibble::tibble(a = 1:10) tbl_check_class() tbl_grade_class() .result <- tibble::tibble(a = 1:10, b = a %% 2 == 0) .solution <- dplyr::group_by(tibble::tibble(a = 1:10, b = a %% 2 == 0), b) tbl_check_class() tbl_grade_class() # Ignore the difference between tibble and data frame .result <- data.frame(a = 1:10) .solution <- tibble::tibble(a = 1:10) tbl_check_class(ignore_class = c("tbl_df", "tbl")) tbl_grade_class(ignore_class = c("tbl_df", "tbl")) # Ignore the difference between integer and double .result <- 1L .solution <- 1 vec_check_class(ignore_class = c("integer" = "numeric")) vec_grade_class(ignore_class = c("integer" = "numeric")).result <- 1:10 .solution <- as.character(1:10) vec_check_class() vec_grade_class() .result <- data.frame(a = 1:10) .solution <- tibble::tibble(a = 1:10) tbl_check_class() tbl_grade_class() .result <- tibble::tibble(a = 1:10, b = a %% 2 == 0) .solution <- dplyr::group_by(tibble::tibble(a = 1:10, b = a %% 2 == 0), b) tbl_check_class() tbl_grade_class() # Ignore the difference between tibble and data frame .result <- data.frame(a = 1:10) .solution <- tibble::tibble(a = 1:10) tbl_check_class(ignore_class = c("tbl_df", "tbl")) tbl_grade_class(ignore_class = c("tbl_df", "tbl")) # Ignore the difference between integer and double .result <- 1L .solution <- 1 vec_check_class(ignore_class = c("integer" = "numeric")) vec_grade_class(ignore_class = c("integer" = "numeric"))
Checks for differences between the name column in object and in
expected in the following order:
Check that the name column exists in object
Check class with vec_check_class()
Check length with vec_check_dimensions()
If the column is a factor, check factor levels with vec_check_levels()
Check column values with vec_check_values()
If the columns differ
tbl_check_column() returns a list describing the problem
tbl_grade_column() returns a failing grade and informative message
with gradethis::fail()
tbl_check_column( column, object = .result, expected = .solution, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = FALSE, env = parent.frame() ) tbl_grade_column( column, object = .result, expected = .solution, max_diffs = 3, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = FALSE, env = parent.frame(), ... )tbl_check_column( column, object = .result, expected = .solution, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = FALSE, env = parent.frame() ) tbl_grade_column( column, object = .result, expected = .solution, max_diffs = 3, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = FALSE, env = parent.frame(), ... )
column |
|
object |
A data frame to be compared to |
expected |
A data frame containing the expected result. |
check_class |
|
ignore_class |
If an element is named, differences will only be ignored between the pair
of the element and its name.
For example, If all the classes of |
check_length |
|
check_levels |
|
check_values |
|
tolerance |
|
check_names |
|
env |
The environment in which to find |
max_diffs |
|
... |
Arguments passed on to
|
If there are any issues, a list from tbl_check_column() or a
gradethis::fail() message from tbl_grade_column().
Otherwise, invisibly returns NULL.
names (table_problem): object doesn't contain a column named column.
class: Any mismatch in the classes of the column.
length: The column doesn't have the expected length.
levels_n, levels, levels_reversed, levels_order:
See vec_check_levels().
values: The column doesn't have the expected values.
names (column_problem): The column has different names
than expected.
names_order: The column has the same names as expected,
but in a different order.
.result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = letters[1:10], b = letters[11:20]) tbl_check_column("a") tbl_grade_column("a") .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 1:11, b = 12:22) tbl_check_column("a") tbl_grade_column("a") .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 11:20, b = 1:10) tbl_check_column("a") tbl_grade_column("a") tbl_grade_column("a", max_diffs = 5) tbl_grade_column("a", max_diffs = Inf).result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = letters[1:10], b = letters[11:20]) tbl_check_column("a") tbl_grade_column("a") .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 1:11, b = 12:22) tbl_check_column("a") tbl_grade_column("a") .result <- tibble::tibble(a = 1:10, b = 11:20) .solution <- tibble::tibble(a = 11:20, b = 1:10) tbl_check_column("a") tbl_grade_column("a") tbl_grade_column("a", max_diffs = 5) tbl_grade_column("a", max_diffs = Inf)
Checks if object and expected have the same dimenisons.
If the dimensions differ
tbl_check_dimensions() returns a list describing the problem
tbl_grade_dimensions() returns a failing grade and informative message
with gradethis::fail()
tbl_check_dimensions( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame() ) vec_check_dimensions( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame() ) vec_check_length( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame() ) tbl_grade_dimensions( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame(), ... ) vec_grade_dimensions( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame(), ... ) vec_grade_length( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame(), ... )tbl_check_dimensions( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame() ) vec_check_dimensions( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame() ) vec_check_length( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame() ) tbl_grade_dimensions( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame(), ... ) vec_grade_dimensions( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame(), ... ) vec_grade_length( object = .result, expected = .solution, check_ncol = TRUE, env = parent.frame(), ... )
object |
An object to be compared to |
expected |
An object containing the expected result. |
check_ncol |
|
env |
The environment in which to find |
... |
Arguments passed on to
|
If there are any issues, a list from tbl_check_dimensions() or a
gradethis::fail() message from tbl_grade_dimensions().
Otherwise, invisibly returns NULL.
dimensions_n: object and expected have a different number
of dimensions
length: object and expected are one-dimensional vectors of
different lengths
ncol: object and expected are two-dimensional objects with a
different number of columns
nrow: object and expected are two-dimensional objects with a
different number of rows
dimensions: object and expected are multi-dimensional arrays with
different dimensions
.result <- 1:10 .solution <- 1:5 tbl_check_dimensions() tbl_grade_dimensions() .result <- tibble::tibble(a = 1:10, b = 1:10, c = 1:10) .solution <- tibble::tibble(a = 1:10, b = 1:10) tbl_check_dimensions() tbl_grade_dimensions() .result <- tibble::tibble(a = 1:10, b = 1:10) .solution <- tibble::tibble(a = 1:5, b = 1:5) tbl_check_dimensions() tbl_grade_dimensions() .result <- 1:12 .solution <- matrix(1:12, 3) tbl_check_dimensions() tbl_grade_dimensions().result <- 1:10 .solution <- 1:5 tbl_check_dimensions() tbl_grade_dimensions() .result <- tibble::tibble(a = 1:10, b = 1:10, c = 1:10) .solution <- tibble::tibble(a = 1:10, b = 1:10) tbl_check_dimensions() tbl_grade_dimensions() .result <- tibble::tibble(a = 1:10, b = 1:10) .solution <- tibble::tibble(a = 1:5, b = 1:5) tbl_check_dimensions() tbl_grade_dimensions() .result <- 1:12 .solution <- matrix(1:12, 3) tbl_check_dimensions() tbl_grade_dimensions()
Checks if object and expected have the same groups.
If the groups differ
tbl_check_groups() returns a list describing the problem
tbl_grade_groups() returns a failing grade and informative message
with gradethis::fail()
tbl_check_groups(object = .result, expected = .solution, env = parent.frame()) tbl_grade_groups( object = .result, expected = .solution, max_diffs = 3, env = parent.frame(), ... )tbl_check_groups(object = .result, expected = .solution, env = parent.frame()) tbl_grade_groups( object = .result, expected = .solution, max_diffs = 3, env = parent.frame(), ... )
object |
An object to be compared to |
expected |
An object containing the expected result. |
env |
The environment in which to find |
max_diffs |
|
... |
Arguments passed on to
|
If there are any issues, a list from tbl_check_groups() or a
gradethis::fail() message from tbl_grade_groups().
Otherwise, invisibly returns NULL.
groups: The object has groups that are not expected,
or is missing groups that are expected.
.result <- dplyr::group_by(tibble::tibble(a = 1:10, b = 11:20), a) .solution <- dplyr::group_by(tibble::tibble(a = 1:10, b = 11:20), b) tbl_check_groups() tbl_grade_groups().result <- dplyr::group_by(tibble::tibble(a = 1:10, b = 11:20), a) .solution <- dplyr::group_by(tibble::tibble(a = 1:10, b = 11:20), b) tbl_check_groups() tbl_grade_groups()
Checks if object inherits the data.frame class.
If the not
tbl_check_is_table() returns a list describing the problem
tbl_grade_is_table() returns a failing grade and
informative message with gradethis::fail()
tbl_check_is_table(object = .result, env = parent.frame()) tbl_grade_is_table(object = .result, env = parent.frame(), ...)tbl_check_is_table(object = .result, env = parent.frame()) tbl_grade_is_table(object = .result, env = parent.frame(), ...)
object |
An object to be compared to |
env |
The environment in which to find |
... |
Arguments passed on to
|
If there are any issues, a list from tbl_check_is_table() or a
gradethis::fail() message from tbl_grade_is_table().
Otherwise, invisibly returns NULL.
not_table: The object is not a table
.result <- data.frame(a = 1:10) tbl_check_is_table() tbl_grade_is_table() .result <- tibble::tibble(a = 1:10) tbl_check_is_table() tbl_grade_is_table() .result <- list(a = 1:10) tbl_check_is_table() tbl_grade_is_table().result <- data.frame(a = 1:10) tbl_check_is_table() tbl_grade_is_table() .result <- tibble::tibble(a = 1:10) tbl_check_is_table() tbl_grade_is_table() .result <- list(a = 1:10) tbl_check_is_table() tbl_grade_is_table()
Checks if object and expected have the same names.
If the names differ
tbl_check_names() and vec_check_names() returns a list describing
the problem
tbl_grade_names() and vec_grade_names() returns a failing grade and
informative message with gradethis::fail()
tbl_check_names( object = .result, expected = .solution, check_order = TRUE, env = parent.frame() ) vec_check_names( object = .result, expected = .solution, check_order = TRUE, env = parent.frame() ) tbl_grade_names( object = .result, expected = .solution, max_diffs = 3, check_order = TRUE, env = parent.frame(), ... ) vec_grade_names( object = .result, expected = .solution, max_diffs = 3, check_order = TRUE, env = parent.frame(), ... )tbl_check_names( object = .result, expected = .solution, check_order = TRUE, env = parent.frame() ) vec_check_names( object = .result, expected = .solution, check_order = TRUE, env = parent.frame() ) tbl_grade_names( object = .result, expected = .solution, max_diffs = 3, check_order = TRUE, env = parent.frame(), ... ) vec_grade_names( object = .result, expected = .solution, max_diffs = 3, check_order = TRUE, env = parent.frame(), ... )
object |
An object to be compared to |
expected |
An object containing the expected result. |
check_order |
|
env |
The environment in which to find |
max_diffs |
|
... |
Arguments passed on to
|
If there are any issues, a list from tbl_check_names() and
vec_check_names() or a gradethis::fail() message from
tbl_grade_names() and vec_grade_names().
Otherwise, invisibly returns NULL.
names: The object has names that are not expected,
or is missing names that are expected.
names_order: The object has the same names as expected,
but in a different order.
.result <- c(1, 2, 3, 4, 5, 6, 7) .solution <- c(a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7) vec_check_names() vec_grade_names() vec_grade_names(max_diffs = 5) vec_grade_names(max_diffs = Inf) .result <- tibble::tibble(a = 1:5, b = 6:10, c = 11:15) .solution <- tibble::tibble(a = 1:5, x = 6:10, y = 11:15) tbl_check_names() tbl_grade_names().result <- c(1, 2, 3, 4, 5, 6, 7) .solution <- c(a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7) vec_check_names() vec_grade_names() vec_grade_names(max_diffs = 5) vec_grade_names(max_diffs = Inf) .result <- tibble::tibble(a = 1:5, b = 6:10, c = 11:15) .solution <- tibble::tibble(a = 1:5, x = 6:10, y = 11:15) tbl_check_names() tbl_grade_names()
Test if two tables are equivalent using the same process as tbl_check().
Unlike tbl_check(), which returns either a problem object or NULL,
tbl_equal() returns either TRUE or FALSE.
tbl_equal( object = .result, expected = .solution, 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_levels = check_columns, check_column_values = check_columns, tolerance = sqrt(.Machine$double.eps), check_row_order = check_columns, env = parent.frame() )tbl_equal( object = .result, expected = .solution, 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_levels = check_columns, check_column_values = check_columns, tolerance = sqrt(.Machine$double.eps), check_row_order = check_columns, env = parent.frame() )
object |
A data frame to be compared to |
expected |
A data frame containing the expected result. |
cols |
[ |
check_class |
|
ignore_class |
If an element is named, differences will only be ignored between the pair
of the element and its name.
For example, If all the classes of |
check_names |
|
check_column_order |
|
check_dimensions |
|
check_groups |
|
check_columns |
|
check_column_class |
|
check_column_levels |
|
check_column_values |
|
tolerance |
|
check_row_order |
|
env |
The environment in which to find |
tbl_equal( data.frame(a = 1:10, b = 11:20), data.frame(b = 11:20, a = 1:10) )tbl_equal( data.frame(a = 1:10, b = 11:20), data.frame(b = 11:20, a = 1:10) )
Checks for differences between object and expected in the following order:
Check class with vec_check_class()
Check length with vec_check_dimensions()
If the vector is a factor, check factor levels are the same with vec_check_levels()
Check vector values are the same with vec_check_values()
Check names with vec_check_names()
If the vectors differ
vec_check() returns a list describing the problem
vec_grade() returns a failing grade and informative message
with gradethis::fail()
vec_check( object = .result, expected = .solution, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = TRUE, env = parent.frame() ) vec_grade( object = .result, expected = .solution, max_diffs = 3, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = TRUE, env = parent.frame(), ... )vec_check( object = .result, expected = .solution, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = TRUE, env = parent.frame() ) vec_grade( object = .result, expected = .solution, max_diffs = 3, check_class = TRUE, ignore_class = NULL, check_length = TRUE, check_levels = TRUE, check_values = TRUE, tolerance = sqrt(.Machine$double.eps), check_names = TRUE, env = parent.frame(), ... )
object |
A vector to be compared to |
expected |
A vector containing the expected result. |
check_class |
|
ignore_class |
If an element is named, differences will only be ignored between the pair
of the element and its name.
For example, If all the classes of |
check_length |
|
check_levels |
|
check_values |
|
tolerance |
|
check_names |
|
env |
The environment in which to find |
max_diffs |
|
... |
Arguments passed on to
|
If there are any issues, a list from vec_check() or a
gradethis::fail() message from vec_grade().
Otherwise, invisibly returns NULL.
class: object doesn't have the same classes as expected.
length: object doesn't have the same length as expected.
levels_n, levels, levels_reversed, levels_order:
See vec_check_levels().
values: object doesn't contain the same values as expected.
names: object has different names than expected.
names_order: object has the same names as expected,
but in a different order.
.result <- 1:10 .solution <- letters[1:10] vec_check() vec_grade() .result <- 1:10 .solution <- 1:11 vec_check() vec_grade() .result <- 1:10 .solution <- rlang::set_names(1:10, letters[1:10]) vec_check() vec_grade() vec_grade(max_diffs = 5) vec_grade(max_diffs = Inf) .result <- 1:10 .solution <- 11:20 vec_check() vec_grade() vec_grade(max_diffs = 5) vec_grade(max_diffs = Inf).result <- 1:10 .solution <- letters[1:10] vec_check() vec_grade() .result <- 1:10 .solution <- 1:11 vec_check() vec_grade() .result <- 1:10 .solution <- rlang::set_names(1:10, letters[1:10]) vec_check() vec_grade() vec_grade(max_diffs = 5) vec_grade(max_diffs = Inf) .result <- 1:10 .solution <- 11:20 vec_check() vec_grade() vec_grade(max_diffs = 5) vec_grade(max_diffs = Inf)
Checks if object and expected have the same levels.
If the levels differ
vec_check_levels() returns a list describing the problem
vec_grade_levels() returns a failing grade and informative message
with gradethis::fail()
vec_check_levels(object = .result, expected = .solution, env = parent.frame()) vec_grade_levels( object = .result, expected = .solution, max_diffs = 3, env = parent.frame(), ... )vec_check_levels(object = .result, expected = .solution, env = parent.frame()) vec_grade_levels( object = .result, expected = .solution, max_diffs = 3, env = parent.frame(), ... )
object |
An object to be compared to |
expected |
An object containing the expected result. |
env |
The environment in which to find |
max_diffs |
|
... |
Arguments passed on to
|
If there are any issues, a list from vec_check_levels() or a
gradethis::fail() message from vec_grade_levels().
Otherwise, invisibly returns NULL.
levels_n: object and expected have a different number of levels.
levels: The object has levels that are not expected,
or is missing levels that are expected.
levels_reversed: The levels of object are in the opposite order
of expected.
level_order: The levels of object are not in the same order
as expected.
.result <- as.factor(rep_len(letters[1:3], 6)) .solution <- as.factor(rep_len(letters[1:2], 6)) vec_check_levels() vec_grade_levels() .result <- as.factor(letters[1:6]) .solution <- as.factor(letters[21:26]) vec_check_levels() vec_grade_levels() vec_grade_levels(max_diffs = 5) vec_grade_levels(max_diffs = Inf).result <- as.factor(rep_len(letters[1:3], 6)) .solution <- as.factor(rep_len(letters[1:2], 6)) vec_check_levels() vec_grade_levels() .result <- as.factor(letters[1:6]) .solution <- as.factor(letters[21:26]) vec_check_levels() vec_grade_levels() vec_grade_levels(max_diffs = 5) vec_grade_levels(max_diffs = Inf)
Check if two vectors contain the same values. If the values differ
vec_check_values() returns a list describing the problem
vec_grade_values() returns a failing grade and informative message
with gradethis::fail()
vec_check_values( object = .result, expected = .solution, tolerance = sqrt(.Machine$double.eps), env = parent.frame() ) vec_grade_values( object = .result, expected = .solution, tolerance = sqrt(.Machine$double.eps), max_diffs = 3, env = parent.frame(), ... )vec_check_values( object = .result, expected = .solution, tolerance = sqrt(.Machine$double.eps), env = parent.frame() ) vec_grade_values( object = .result, expected = .solution, tolerance = sqrt(.Machine$double.eps), max_diffs = 3, env = parent.frame(), ... )
object |
A vector to be compared to |
expected |
A vector containing the expected result. |
tolerance |
|
env |
The environment in which to find |
max_diffs |
|
... |
Arguments passed on to
|
If there are any issues, a list from vec_check_values() or a
gradethis::fail() message from vec_grade_values().
Otherwise, invisibly returns NULL.
values: object doesn't contain the same values as expected
.result <- 1:10 .solution <- letters[1:10] vec_check_values() vec_grade_values() .result <- 1:10 .solution <- 1:11 vec_check_values() vec_grade_values() .result <- 1:10 .solution <- rlang::set_names(1:10, letters[1:10]) vec_check_values() vec_grade_values() vec_grade_values(max_diffs = 5) vec_grade_values(max_diffs = Inf) .result <- 1:10 .solution <- 11:20 vec_check_values() vec_grade_values() vec_grade_values(max_diffs = 5) vec_grade_values(max_diffs = Inf).result <- 1:10 .solution <- letters[1:10] vec_check_values() vec_grade_values() .result <- 1:10 .solution <- 1:11 vec_check_values() vec_grade_values() .result <- 1:10 .solution <- rlang::set_names(1:10, letters[1:10]) vec_check_values() vec_grade_values() vec_grade_values(max_diffs = 5) vec_grade_values(max_diffs = Inf) .result <- 1:10 .solution <- 11:20 vec_check_values() vec_grade_values() vec_grade_values(max_diffs = 5) vec_grade_values(max_diffs = Inf)