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, env = parent.frame())
vec_grade_values(
object = .result,
expected = .solution,
max_diffs = 3,
env = parent.frame(),
...
)
A vector to be compared to expected
.
A vector containing the expected result.
The environment in which to find .result
and .solution
.
[numeric(1)]
The maximum number of mismatched values to
print. Defaults to 3.
Arguments passed on to gradethis::fail
hint
Include a code feedback hint with the failing message? This
argument only applies to fail()
and fail_if_equal()
and the message is
added using the default options of give_code_feedback()
and
maybe_code_feedback()
. The default value of hint
can be set using
gradethis_setup()
or the gradethis.fail.hint
option.
encourage
Incude a random encouraging phrase with
random_encouragement()
? The default value of encourage
can be set
using gradethis_setup()
or the gradethis.fail.encourage
option.
If there are any issues, a list from vec_check_values()
or a
gradethis::fail()
message from vec_grade_values()
.
Otherwise, invisibly returns NULL
.
.result <- 1:10
.solution <- letters[1:10]
vec_check_values()
#> <tblcheck problem>
#> Your result should be a vector of text (class `character`), but it is a vector of integers (class `integer`).
#> $ type : chr "class"
#> $ expected : chr "character"
#> $ actual : chr "integer"
#> $ expected_length: int 10
#> $ actual_length : int 10
vec_grade_values()
#> <gradethis_graded: [Incorrect]
#> Your result should be a vector of text (class `character`), but
#> it is a vector of integers (class `integer`).
#> >
.result <- 1:10
.solution <- 1:11
vec_check_values()
#> <tblcheck problem>
#> Your result should contain 11 values, but it has 10 values. I expected your result to include the value `11`.
#> $ type : chr "length"
#> $ expected : int [1:11] 1 2 3 4 5 6 7 8 9 10 ...
#> $ actual : int [1:10] 1 2 3 4 5 6 7 8 9 10
#> $ expected_length: int 11
#> $ actual_length : int 10
vec_grade_values()
#> <gradethis_graded: [Incorrect]
#> Your result should contain 11 values, but it has 10 values. I
#> expected your result to include the value `11`.
#> >
.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()
#> <tblcheck problem>
#> The first 3 values of your result should be `11`, `12`, and `13`, not `1`, `2`, and `3`.
#> $ type : chr "values"
#> $ expected: int [1:10] 11 12 13 14 15 16 17 18 19 20
#> $ actual : int [1:10] 1 2 3 4 5 6 7 8 9 10
vec_grade_values()
#> <gradethis_graded: [Incorrect]
#> The first 3 values of your result should be `11`, `12`, and
#> `13`, not `1`, `2`, and `3`.
#> >
vec_grade_values(max_diffs = 5)
#> <gradethis_graded: [Incorrect]
#> The first 5 values of your result should be `11`, `12`, `13`,
#> `14`, and `15`, not `1`, `2`, `3`, `4`, and `5`.
#> >
vec_grade_values(max_diffs = Inf)
#> <gradethis_graded: [Incorrect]
#> The first 10 values of your result should be `11`, `12`, `13`,
#> `14`, `15`, `16`, `17`, `18`, `19`, and `20`, not `1`, `2`,
#> `3`, `4`, `5`, `6`, `7`, `8`, `9`, and `10`.
#> >