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