tbl_check | R Documentation |
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(), ... )
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.