Assert that a distance table is complete and square
Source:R/pairwise_distances_class.R
distances_assert_square.RdChecks that the table holds every ordered pair of the ids it contains —
n^2 rows for n ids. Phrased over the ids present, so that a
symmetric subset stays square: filtering both id columns to the same set of
entities preserves this, while filtering one of them does not.
Details
Squareness is a precondition of the functions that need it. The class itself does not require it, because filtering the two id columns one after the other passes through a legitimate non-square intermediate.
See also
Other pairwise distances:
[.pairwise_distances(),
as.matrix.pairwise_distances(),
distances_restrict(),
is_pairwise_distances(),
pairwise_distances(),
rvd_dna_specificity,
tales_assign_domain_codes(),
tales_compare_distal(),
tales_compare_functal(),
tales_domain_distances(),
tales_group_hclust(),
tales_group_kmedoids(),
tales_tale_distances(),
validate_pairwise_distances()
Examples
d <- pairwise_distances(data.frame(
id1 = c("A1", "A1", "A2", "A2"),
id2 = c("A1", "A2", "A1", "A2"),
dissim = c(0, 35, 35, 0)
))
distances_assert_square(d)
try(distances_assert_square(d[1:3, ])) # missing the A2-A2 pair -- errors
#> Error in distances_assert_square(d[1:3, ]) :
#> `x` must hold every pair of the 2 ids it contains (4 rows), but has 3.
#> ℹ Filtering both id columns to the same entities keeps a table square;
#> filtering one does not.