Document expected cardinality

Current dplyr joins support a relationship argument. If each row in the left table should match at most one row in the right table, declare many-to-one. Check unmatched keys separately; a cardinality assertion does not establish that every expected match exists.

Technical background: [1]. Practical recommendations below are VSPJ Consulting commentary.

Keep the failed example

When an assertion fails, preserve a minimal synthetic example and clarify the key. Do not remove the check just to complete the pipeline. Repeated subject identifiers may be legitimate when the real key also includes a visit or parameter.

Illustrative example

dplyr::left_join(
  labs, subjects,
  by = "USUBJID",
  relationship = "many-to-one"
)

Review and test this example against your own inputs and specification before use.

Sources & further reading

  1. dplyr — Mutating joins

References reviewed 21 September 2026. Sources support the technical background; workflow recommendations are independent implementation commentary. Release-watch details are dated snapshots. Check current documentation before adoption.

Have a related programming or implementation challenge?

Discuss it with Sai Prasad ↗