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
Split the current JoinKeys object into a named list of join keys objects with an element for each dataset
Returns
(list) a list of JoinKeys object
Merging a list (or one) of JoinKeys objects into the current JoinKeys object
Arguments
x
list of JoinKeys objects or single JoinKeys object
Returns
(self) invisibly for chaining
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.
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
Prints this JoinKeys.
Arguments
...
additional arguments to the printing method
Method set_parents()
Sets the parents of the datasets.
Usage
JoinKeys$set_parents(named_list)
Arguments
named_list
Named (list) of the parents datasets.
Returns
(self) invisibly for chaining
Method get_parent()
Gets the parent of the desired dataset.
Usage
JoinKeys$get_parent(dataname)
Arguments
dataname
(character) name of the dataset.
Returns
(character) the parent of the desired dataset
Method get_parents()
Gets the parents of the datasets.
Returns
(list) A named list of the parents of all datasets
Method update_keys_given_parents()
Updates the keys of the datasets based on the parents.
Usage
JoinKeys$update_keys_given_parents()
Returns
(self) invisibly for chaining
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"