Title: | Perform "Safe" Table Joins |
Version: | 0.2.0 |
Description: | The goal of 'safejoin' is to guarantee that when performing joins extra rows are not added to your data. 'safejoin' provides a wrapper around 'dplyr::left_join' that will raise an error when extra rows are unexpectedly added to your data. This can be useful when working with data where you expect there to be a many to one relationship but you are not certain the relationship holds. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
Suggests: | testthat, knitr, rmarkdown |
Imports: | dplyr, glue, lifecycle |
RoxygenNote: | 7.2.3 |
URL: | https://github.com/SamEdwardes/safejoin |
BugReports: | https://github.com/SamEdwardes/safejoin/issues |
NeedsCompilation: | no |
Packaged: | 2024-06-02 20:39:36 UTC; samedwardes |
Author: | Sam Edwardes [aut, cre] |
Maintainer: | Sam Edwardes <edwardes.s@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2024-06-02 21:10:03 UTC |
safejoin: Perform "Safe" Table Joins
Description
The goal of 'safejoin' is to guarantee that when performing joins extra rows are not added to your data. 'safejoin' provides a wrapper around 'dplyr::left_join' that will raise an error when extra rows are unexpectedly added to your data. This can be useful when working with data where you expect there to be a many to one relationship but you are not certain the relationship holds.
Author(s)
Maintainer: Sam Edwardes edwardes.s@gmail.com
See Also
Useful links:
Report bugs at https://github.com/SamEdwardes/safejoin/issues
Validate extra rows are added not added to the left hand side
Description
Perform a "safe" left join where it is guaranteed that no additional rows are
added to the left hand side table. For more information on left joins see
(
dplyr::left_join
).
Usage
safe_left_join(..., action = "error", relationship = "*:1")
Arguments
... |
Arguments passed on to
|
action |
What should happen when the number of rows changes from a join? Options include: 'error', 'warning', or 'message'. By default 'error'. |
relationship |
What is the expected relationship between |
Value
An object of the same type as x
. The order of the rows and columns of x
is preserved as much as possible. The output has the following properties:
Examples
# The relationship between `x` and `y` is '*:1'. No extra rows will be added
# to the left hand side.
x <- data.frame(key = c("a", "a", "b"), value_x = c(1, 4, 2))
y <- data.frame(key = c("a", "b"), value_y = c(1, 1))
safe_left_join(x, y)
# The relationship between `x` and `y` is '1:*'. An error should be raised
# because additional rows will be added to the left hand side.
## Not run: x <- data.frame(key = c("a", "b"), value_x = c(1, 2))
y <- data.frame(key = c("a", "a"), value_y = c(1, 1))
safe_left_join(x, y)
## End(Not run)
# Alternatively instead of raising an error a warning or message can be
# outputted.
x <- data.frame(key = c("a", "b"), value_x = c(1, 2))
y <- data.frame(key = c("a", "a"), value_y = c(1, 1))
safe_left_join(x, y, action = "warning")
safe_left_join(x, y, action = "message")