are_same_length: Are the inputs the same length/dimension?

View source: R/are-same-size.R

are_same_lengthR Documentation

Are the inputs the same length/dimension?

Description

Checks if the inputs are the same length, or have the same dimensions.

Usage

are_same_length(
  x,
  y,
  .xname = get_name_in_parent(x),
  .yname = get_name_in_parent(y)
)

have_same_dims(
  x,
  y,
  .xname = get_name_in_parent(x),
  .yname = get_name_in_parent(y)
)

are_same_length_legacy(..., l = list())

assert_are_same_length(
  x,
  y,
  severity = getOption("assertive.severity", "stop")
)

assert_have_same_dims(x, y, severity = getOption("assertive.severity", "stop"))

assert_all_are_same_length_legacy(..., l = list())

assert_all_are_same_length(..., l = list())

assert_any_are_same_length_legacy(..., l = list())

assert_any_are_same_length(..., l = list())

Arguments

x

An R object or expression.

y

Another R object or expression.

.xname

Not intended to be used directly.

.yname

Not intended to be used directly.

...

Some R expressions.

l

A list of R expressions.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

Value

are_same_length and have_same_dims return TRUE if x and y have the same length, or their dimensions are identical. The assert_* functions throw an error on failure.

The legacy function are_same_length_legacy allows an arbitrary number of inputs and returns a symmetric square logical matrix which is TRUE where pairs of inputs are the same length. (The new version of the function is easier to work with, and it is recommended that you switch your code to it.)

See Also

length, are_identical

Examples

are_same_length(runif(5), list(1, 2:3, 4:6, 7:10, 11:15))
assertive.base::dont_stop(
  assert_are_same_length(runif(6), list(1, 2:3, 4:6, 7:10, 11:15))
)
have_same_dims(
  matrix(1:12, nrow = 4), 
  data.frame(x = 1:4, y = 5:8, y = 9:12)
)
have_same_dims(1:5, matrix(1:5))

assertive.properties documentation built on April 21, 2022, 5:13 p.m.