Skip to contents

This function determines whether two objects have the same structure, where

  • two lists have the same structure if they have the same length and their elements (compared in order and recursively) have the same mode and length,

  • and two other objects have the same structure if they have the same class and the same dimension (or the same length, if they have no dimension).

Note that concrete values, names, and other attributes are not compared.

Usage

identical_structure(x, y)

Arguments

x, y

[any]
Two objects.

Value

Either TRUE if x and y have the same structure, and FALSE, else.

Examples

identical_structure(integer(1), 1L)
#> [1] TRUE
identical_structure(diag(2), matrix(rnorm(4), 2, 2))
#> [1] TRUE
identical_structure(diag(2), data.frame(diag(2)))
#> [1] FALSE
identical_structure(list(1, "a"), list(2, "b"))
#> [1] TRUE