From 53d1df695246d073b544550df447e2bf7cb9b83e Mon Sep 17 00:00:00 2001 From: go_gonzo Date: Fri, 17 Nov 2023 09:28:40 +0100 Subject: [PATCH] fix test and redact --- R/join_keys.R | 28 ++++++++++++++++------------ tests/testthat/test-join_keys.R | 10 +++++----- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/R/join_keys.R b/R/join_keys.R index 89d6c83c4..d1de53c7f 100644 --- a/R/join_keys.R +++ b/R/join_keys.R @@ -1,23 +1,27 @@ # Constructors ==== -#' Create a `join_keys` out of a list of `join_key_set` objects +#' Manage relationships between datasets using `join_keys` #' -#' @description `r lifecycle::badge("stable")` +#' @description +#' `join_keys()` facilitates the creation and retrieval of relationships between datasets. +#' `join_keys` class extends a list and contains keys connecting pairs of datasets. Each element +#' of the list contains keys for specific dataset. Each dataset can have a relationship with +#' itself (primary key) and with other datasets. #' -#' Note that join keys are created symmetrically, that is, if `dat1` and `dat2` -#' have a join key of `col1`, then 2 join keys are created, `dat1 → dat2` and +#' Note that `join_keys` list is symmetrical, that is, when keys are set between `dat1` and `dat2` it +#' is automatically mirrored between `dat2` and `dat1`. #' `dat2 → dat1`. The only exception is for a primary key. #' #' @details #' -#' - `join_keys()`: When called without arguments it will return an -#' empty constructor. -#' - `join_keys(x)`: When called with a single argument it will return the `join_keys` -#' object contained in `x` (if it contains a `join_keys` object). -#' - `join_keys(...)`: When called with a single or more `join_key_set` parameters it will -#' create a new object. -#' - `[[.join_keys` is the preferred getter for `join_keys` that returns the -#' relationship between pairs of datasets. It returns `NULL` if there is nor +#' - `join_keys()`: Returns an empty `join_keys` object when called without arguments. +#' - `join_keys(x)`: Returns the `join_keys` object contained in `x` (if it contains one). +#' - `join_keys(...)`: Creates a new object with one or more `join_key_set` parameters. +#' - `join_keys[datanames]`: Returns a subset of the `join_keys` object for given datanames, +#' including their symmetric mirror keys. +#' - `join_keys[i, j]`: Returns join keys between datasets `i` and `j`, +#' including implicit keys inferred from their relationship with a parent. +#' #' relationship. #' #' @order 1 diff --git a/tests/testthat/test-join_keys.R b/tests/testthat/test-join_keys.R index 6b9c9733c..e3b7e127c 100644 --- a/tests/testthat/test-join_keys.R +++ b/tests/testthat/test-join_keys.R @@ -124,7 +124,7 @@ testthat::test_that("[[.join_keys doesn't return keys for given a pair without e testthat::expect_null(my_keys[["b"]][["c"]]) }) -testthat::test_that("[[.join_keys infer keys between child by equal (unordered) foreign keys to parent", { +testthat::test_that("[[.join_keys infer keys between children by equal (unordered) foreign keys to parent", { my_keys <- join_keys( join_key("a", "a", "aa"), join_key("b", "b", "bb"), @@ -137,14 +137,14 @@ testthat::test_that("[[.join_keys infer keys between child by equal (unordered) }) testthat::test_that( - "[[.join_keys infer keys between child by shared foreign keys to parent (key names are unique to datasets)", + "[[.join_keys infer keys between children by foreign keys to common parent. ", { my_keys <- join_keys( join_key("a", "a", "aa"), join_key("b", "b", "bb"), join_key("c", "c", "cc"), - join_key("b", "a", c(aa = "bb")), - join_key("c", "a", c(aa = "cc")) + join_key("b", "a", c(bb = "aa")), + join_key("c", "a", c(cc = "aa")) ) parents(my_keys) <- list("b" = "a", "c" = "a") testthat::expect_identical(my_keys["b", "c"], c(bb = "cc")) @@ -205,7 +205,7 @@ testthat::test_that("[.join_keys returns join_keys object for given dataset incl testthat::expect_equal(my_keys["d2"], expected) }) -testthat::test_that("[.join_keys returns join_keys object for given dataset and doesn't include its childs", { +testthat::test_that("[.join_keys returns join_keys object for given dataset and doesn't include its children", { my_keys <- join_keys( join_key("d1", "d1", "a"), join_key("d2", "d2", "b"),