Skip to contents

[Stable] This class stores symmetric links between pairs of key-values (e.g. column A of dataset X can be joined with column B of dataset Y). This relationship is more general than the SQL foreign key relationship which also imposes constraints on the values of these columns.

Methods


Method new()

Create a new object of JoinKeys

Usage

JoinKeys$new()

Returns

empty (JoinKeys)


Method split()

Split the current JoinKeys object into a named list of join keys objects with an element for each dataset

Usage

JoinKeys$split()

Returns

(list) a list of JoinKeys object


Method merge()

Merging a list (or one) of JoinKeys objects into the current JoinKeys object

Usage

JoinKeys$merge(x)

Arguments

x

list of JoinKeys objects or single JoinKeys object

Returns

(self) invisibly for chaining


Method get()

Get join keys between two datasets.

Usage

JoinKeys$get(dataset_1, dataset_2)

Arguments

dataset_1

(character) one dataset name

dataset_2

(character) other dataset name

Details

if one or both of dataset_1 and dataset_2 are missing then underlying keys structure is returned for further processing

Returns

(character) named character vector x with names(x) the columns of dataset_1 and the values of (x) the corresponding join keys in dataset_2 or character(0) if no relationship


Method mutate()

Change join_keys for a given pair of dataset names (or add join_keys for given pair if it does not exist)

Usage

JoinKeys$mutate(dataset_1, dataset_2, val)

Arguments

dataset_1

(character) one dataset name

dataset_2

(character) other dataset name

val

(named character) column names used to join

Returns

(self) invisibly for chaining


Method set()

Set up join keys basing on list of JoinKeySet objects.

Usage

JoinKeys$set(x)

Arguments

x

list of JoinKeySet objects (which are created using the join_key function) or single JoinKeySet objects

Details

Note that join keys are symmetric although the relationship only needs to be specified once

Returns

(self) invisibly for chaining


Method print()

Prints this JoinKeys.

Usage

JoinKeys$print(...)

Arguments

...

additional arguments to the printing method

Returns

invisibly self


Method clone()

The objects of this class are cloneable with this method.

Usage

JoinKeys$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

x <- teal.data:::JoinKeys$new()
x$set(
  list(
    join_key("dataset_A", "dataset_B", c("col_1" = "col_a")),
    join_key("dataset_A", "dataset_C", c("col_2" = "col_x", "col_3" = "col_y"))
  )
)
x$get()
#> $dataset_A
#> $dataset_A$dataset_B
#>   col_1 
#> "col_a" 
#> 
#> $dataset_A$dataset_C
#>   col_2   col_3 
#> "col_x" "col_y" 
#> 
#> 
#> $dataset_B
#> $dataset_B$dataset_A
#>   col_a 
#> "col_1" 
#> 
#> 
#> $dataset_C
#> $dataset_C$dataset_A
#>   col_x   col_y 
#> "col_2" "col_3" 
#> 
#> 
x$mutate("dataset_A", "dataset_B", c("col1" = "col10"))
x$get("dataset_A", "dataset_B")
#>    col1 
#> "col10"