vec_check_values: Checks that two vectors are contain the same values

View source: R/vec_check_values.R

vec_check_valuesR Documentation

Checks that two vectors are contain the same values

Description

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()

Usage

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(),
  ...
)

Arguments

object

A vector to be compared to expected.

expected

A vector containing the expected result.

tolerance

[numeric(1) ≥ 0]
values differences smaller than tolerance are ignored. The default value is close to 1.5e-8.

env

The environment in which to find .result and .solution.

max_diffs

[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

Include a random encouraging phrase with random_encouragement()? The default value of encourage can be set using gradethis_setup() or the gradethis.fail.encourage option.

Value

If there are any issues, a list from vec_check_values() or a gradethis::fail() message from vec_grade_values(). Otherwise, invisibly returns NULL.

Problems

  1. values: object doesn't contain the same values as expected

Examples

.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)

rstudio/tblcheck documentation built on March 11, 2023, 5:42 p.m.