tbl_check_dimensions: Check that the dimensions of two object are the same

View source: R/tbl_check_dimensions.R

tbl_check_dimensionsR Documentation

Check that the dimensions of two object are the same

Description

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

Usage

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

Arguments

object

An object to be compared to expected.

expected

An object containing the expected result.

check_ncol

[logical(1)]
Whether to check that object and expected have the same number of columns.

env

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

...

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 tbl_check_dimensions() or a gradethis::fail() message from tbl_grade_dimensions(). Otherwise, invisibly returns NULL.

Problems

  1. dimensions_n: object and expected have a different number of dimensions

  2. length: object and expected are one-dimensional vectors of different lengths

  3. ncol: object and expected are two-dimensional objects with a different number of columns

  4. nrow: object and expected are two-dimensional objects with a different number of rows

  5. dimensions: object and expected are multi-dimensional arrays with different dimensions

Examples

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

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