Functions for Mapping Key-Value Pairs, Many-to-Many, One-to-Many, and Many-to-One Relations
Overview
Functions to safely map from a vector of keys to a vector of values, determine properties of a given relation, or ensure a relation conforms to a given type, such as many-to-many, one-to-many, injective, surjective, or bijective. Permits default return values for use similar to a vectorised switch statement, as well as safely handling large vectors, NAs, and duplicate mappings.
Features
relatable provides two easy-to-use, robust functions for mapping from
a vector of keys to a vector of values, as well as creating and applying
more sophisticated mappings, such as many-to-many, one-to-many, and
many-to-one relations. These are primarily designed with two goals in
mind:
1. Producing reusable code that is easier to write and read.
2. Ensuring relations conform to specified restrictions, for example
injectivity or surjectivity, and safely handle nonstandard mappings,
including unexpected inputs, NAs, heterogeneous lists containing
multiple variable types including other lists, and mappings between
vectors of uncertain or unequal lengths.
Show all changes in 1.0.0Hide the rest of the changes in 1.0.0
Functions
relate returns a vector *Y = F(X)* where *F* maps each element of
input vector X from its position in vector A to its corresponding
position in vector B. Can be applied as a vectorised key-value
dictionary with an optional default return value. Additional options
restrict mapping types so relation *F* must be a function, injective,
surjective, etc.
relation returns a reusable function *F* that performs the same
operation as relate. In addition to providing a reusable function, if
handle_duplicate_mappings = TRUE, relation checks for and eliminates
duplicate mappings that would be invalid inputs for relate. If
report_properties = TRUE, relation also prints the restrictions the
mapping from A to B conforms to.
From NEWS.md in the release
Install
Health
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK14 OK2026-03-10
Documentation
- Help pages
- 2
- Examples that run
- 100%1 run in a plain check
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 0%
- Help pages citing references
- 0%
- restrictions HTML
Downloads
Repository
Stars over time
3 development-tooling and community-health practices detected across 3 families in the upstream repository
Checks run against github.com/domjarkey/relatable on 2026-10-21.
Dependencies
Installing relatable adds 1 package (0 with compiled code, 399 KB of source tarballs). Heaviest: compare 399 KB.
Code & Tests
Datasets
People & History
- RR 4.6.0 released · 2026-04-24
- RR 4.5.0 released · 2025-04-11
- RR 4.4.0 released · 2024-04-24
- RR 4.3.0 released · 2023-04-21
- RR 4.2.0 released · 2022-04-22
- RR 4.1.0 released · 2021-05-18
- RR 4.0.0 released · 2020-04-24
- RR 3.6.0 released · 2019-04-26
- RR 3.5.0 released · 2018-04-23
- 1.0.0Latest2018-01-30 · current release
- RR 3.4.0 released · 2017-04-21
Package metadata
- First published
- 2018-01-30
- Total releases
- 1 / 8 yrs
- License
- MIT + file LICENSE OSI
- Minimum R
- ≥ 3.4
- Bundled data
- 1.2 KB / 1 file
- Download size
- 60 KB
Cite
Cite this package
Run in R for the authors' preferred citation:
citation("relatable")This package has no citation file, so citation() returns this entry built from DESCRIPTION.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-25, which the citation names so these numbers can be found later. More on citing and the projects behind them.