This function will return TRUE whenever base::all.equal() would return TRUE, however it will also return TRUE in some other cases:

  • If a is given and b is not, TRUE will be returned if all of the elements of a are the same.

  • If a is a scalar and b is a vector or array, TRUE will be returned if every element in b is equal to a.

  • If a is a vector or array and b is a scalar, TRUE will be returned if every element in a is equal to b.

This function ignores names and attributes (except for dim).

When this function does not return TRUE, it returns FALSE (unless it errors). This is unlike base::all.equal().

all_equal(a, b = NULL)

Arguments

a

A vector, array or list.

b

Either NULL or a vector, array or list of length either 1 or length(a).

Value

TRUE if "equality of all" is satisfied (as detailed in 'Description' above) and FALSE otherwise.

Note

Examples

all_equal(1, rep(1, 3))
#> [1] TRUE
all_equal(2, 1:3)
#> [1] FALSE
all_equal(1:4, 1:4)
#> [1] TRUE
all_equal(1:4, c(1, 2, 3, 3))
#> [1] FALSE
all_equal(rep(1, 10))
#> [1] TRUE
all_equal(c(1, 88))
#> [1] FALSE
all_equal(1:2)
#> [1] FALSE
all_equal(list(1:2))
#> [1] TRUE
all_equal(1:4, matrix(1:4, nrow = 2)) # note that this gives TRUE
#> [1] FALSE