Skip to content

Commit 6cd34d7

Browse files
committed
docs: correction and adds join_key merge section
1 parent 3d47e3f commit 6cd34d7

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

vignettes/join-keys.Rmd

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ As the _Constructor_ it is used to specify a collection of multiple individual k
5353
Specifies a primary key or a relationship between two datasets.
5454

5555
- `dataset_1`, `dataset_2`: names of the datasets (if `dataset_2` is the same as `dataset_1` or is omitted, it creates a primary key);
56-
- `key` (optional): named vector of column names;
57-
- `parent` (optional): indicates which dataset (`"dataset_1"` or `"dataset_2"`) is the parent in a _parent-child_ relationship, or `"none"` for an undirected relationship.
56+
- `key`: named character vector of column name mapping between datasets (unnamed vector assumes column names between datasets are the same);
57+
- `directed` (optional): flag that indicates whether there is a _parent-child_ directed relationship between `dataset_2` to `dataset_1` (latter as a parent).
5858

5959
Note that join keys are assumed to be symmetric, i.e., `join_key("ds1", "ds2", c("ds1_col" = "ds2_col"))` establishes a relationship from "x" to "y" and vice versa.
6060

@@ -132,7 +132,7 @@ When only 1 argument is used this operator will return a `join_keys` object that
132132
jk
133133
134134
# Getting primary key of "ds1"
135-
jk["ds1"]
135+
jk["ds1", "ds1"]
136136
137137
# Getting keys of "ds1" and "ds2"
138138
jk[c("ds1", "ds2")]
@@ -150,6 +150,26 @@ jk["ds1", "ds5"] <- "a_column"
150150
jk["ds4", "ds5"] <- NULL
151151
```
152152

153+
## Merging Join Keys
154+
155+
The consolidation of multiple _joining keys_ is achieved using the `c()` generic function, which generates a symmetric and valid `join_keys` object. When encountering identical relationship pairs, this operation retains the last occurrence of the pair within the specified argument order.
156+
157+
For added convenience, the function also accommodates `join_key_set` objects created through the `join_key` function. These objects can be provided as the initial argument or in any other position as needed.
158+
159+
```{r}
160+
jk1 <- join_keys(join_key("ds1", "ds1", "col_1"))
161+
jk2 <- join_keys(join_key("ds2", "ds2", "col_1"), join_key("ds1", "ds2", "col_1"))
162+
163+
# Merging
164+
c(jk1, jk2)
165+
166+
# Keeping last occurence
167+
c(jk1, jk2, join_keys(join_key("ds2", "ds2", "col_2"), join_key("ds1", "ds2", c("col_1" = "col_2"))))
168+
169+
# Merges join_key and join_key_set objects (from join_key function)
170+
c(jk1, join_key("ds3", "ds3", "col_3"))
171+
```
172+
153173
## Join Keys Relationships
154174

155175
There are 2 types of relationships encoded with _joining keys_ that are described in the following sections. The _primary_ and _foreign_ keys are created explicitly using the constructor for individual keys (`join_key`).

0 commit comments

Comments
 (0)